首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

获取div光标并安插图片

2013-07-01 
获取div光标并插入图片//显示图片function showImage(div_id,img_src) {//IE supportif (document.selecti

获取div光标并插入图片

//显示图片function showImage(div_id,img_src) {    //IE support      if (document.selection) {    var myField = document.getElementById(div_id);   //对象           var myValue = '<img src = "'+img_src+'"/>';  //值        myField.focus();        var sel = document.selection.createRange();        sel.pasteHTML(myValue);    }else {    var sel = div_range;    if(sel == null || sel == 'undefined'){    myfocus(div_id);    sel = document.getSelection().getRangeAt(0);    }        var img = document.createElement("img");        img.src = img_src;        sel.insertNode(img);    }}var div_range;function divOnmouseout(){var sel = document.getSelection();if(sel){//ff,chdiv_range = sel.getRangeAt(0);}//获取焦点function myfocus(obj) {    if (typeof obj == 'string') obj = document.getElementById(obj);    obj.focus();    if (obj.createTextRange) {//ie        var rtextRange = obj.createTextRange();        if(obj.value == null || obj.value == '') return;        rtextRange.moveStart('character', obj.value.length);        rtextRange.collapse(true);        rtextRange.select();    }else if (obj.selectionStart){//chrome "<input>"、"<textarea>"        obj.selectionStart = obj.value.length;    }else if(window.getSelection){    var sel = window.getSelection();    var tempRange = document.createRange();    if(obj.firstChild == null || obj.firstChild == '') return;    tempRange.setStart(obj.firstChild, obj.firstChild.length);    sel.removeAllRanges();    sel.addRange(tempRange);}}}

热点排行