• append from cursor javascript


    Click Here to Insert

     function IFAdd() {
                    ifobj = window.frames.iframe1;
                    var e = document.getElementById("DropDownList1");
                    bookmark = e.options[e.selectedIndex].value;
                   // bookmark = document.getElementById('HiddenField1').value;
                    // this hidden field hv valueselected value  from drop down 
                    //txt = ifobj.document.createTextNode(bookmark);
                  // ifobj.contentEditable = true;            
                  // ifobj.document.getElementsByTagName('BODY')[0].contentEditable = true;
                   
                  insertAtCaret('textareaid',bookmark);
                    return false;
                }
    
    function insertAtCaret(areaId,text) {
        var txtarea = document.getElementById(areaId);
        var scrollPos = txtarea.scrollTop;
        var strPos = 0;
        var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? 
            "ff" : (document.selection ? "ie" : false ) );
        if (br == "ie") { 
            txtarea.focus();
            var range = document.selection.createRange();
            range.moveStart ('character', -txtarea.value.length);
            strPos = range.text.length;
        }
        else if (br == "ff") strPos = txtarea.selectionStart;
    
        var front = (txtarea.value).substring(0,strPos);  
        var back = (txtarea.value).substring(strPos,txtarea.value.length); 
        txtarea.value=front+text+back;
        strPos = strPos + text.length;
        if (br == "ie") { 
            txtarea.focus();
            var range = document.selection.createRange();
            range.moveStart ('character', -txtarea.value.length);
            range.moveStart ('character', strPos);
            range.moveEnd ('character', 0);
            range.select();
        }
        else if (br == "ff") {
            txtarea.selectionStart = strPos;
            txtarea.selectionEnd = strPos;
            txtarea.focus();
        }
        txtarea.scrollTop = scrollPos;
    }
    
  • 相关阅读:
    lower版购物车模拟
    字典的增删改查和操作
    生成四位验证码
    列表的增删改查和操作
    根据输入字符串,分别计算大写,小写,数字,标点的个数
    检查一个数是不是质数
    非诚勿扰,选心动女生(小游戏)
    汉诺塔的实现
    一个纯虚函数导致的问题
    Hello World 之 CGAL
  • 原文地址:https://www.cnblogs.com/happy-Chen/p/3641351.html
Copyright © 2020-2023  润新知