网上找到的都是IE的  ,,我想要通用的  ~~~

解决方案 »

  1.   

    http://www.chenjiliang.com/Article/View.aspx?ArticleID=3003这个  里面的方法只支持 IE   不支持 ff
      

  2.   

    if(IframeSendMsg.getSelection){ 
                range=IframeSendMsg.getSelection().getRangeAt(0);    
            }else if(window.document.selection){ 
                range=IframeSendMsg.document.selection.createRange();
            }
            var doc = IframeSendMsg.document || window.document;
            if(range.pasteHTML)
            {
    range.pasteHTML('<b>asdfas</b>');
    }else{
    var img=doc.createElement("img");
    img.src="";
    range.surroundContents(img);
    }
      

  3.   

    获取光标所在位置的方法 document.selection.createRange()
    只使用于Ie浏览器,ff有他自己的方法。lz只要把这串代码做个浏览器分类就好了
      

  4.   

    对于这个的修改版:http://www.chenjiliang.com/Article/View.aspx?ArticleID=3003
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Div 光标位置 插入 文字 或 HTML</title>
    <script language="javascript" type="text/javascript">
    var pos;
        function getPos()
        {
    if(!!document.all){
    pos = document.selection.createRange();
    }else
    pos = window.getSelection();
        }    function fn_insertPos(_text)
        {     
            if(pos!=null)
            {
                pos.text=_text; if(!document.all){
    var _L=pos.anchorNode.textContent;
    var _O=pos.anchorOffset;
    pos.anchorNode.textContent=_L.substring(0,_O)+_text+_L.substring(_O,_L.length);
    }
    //释放位置
    pos=null;

            }
            else
            {
                alert("没有正确选择位置");
            }        
        }
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div id="myDiv" style="width: 300px; height: 100px; 
              border: black 1px solid; font-size:small; line-height:1; "
              onclick="getPos();"   onkeyup="getPos();"  contenteditable="true">
              一二三四五六七八</div>
            <input id="Button1" type="button" onclick="fn_insertPos('*');" 
             value="点击本按钮在Div中插入相关内容" />              
        </form>
    </body>
    </html>