测试代码如下 ff下是没问题的ie下非要选取了文字才可以 因为用的是pasteHTML嘛  只能选取我希望的是 不选取 在光标处插入html(就跟ff下的效果一样);
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<head>
<script>
var ed = null;
window.onload = function() {
    var o = document.getElementById("ss"); 
    ed = document.all?o.contentWindow.document:o.contentDocument;
    ed.open();
    ed.write('<html><head><style>html,body{margin:5px;font:14px;word-wrap:break-word}</style></head><body id="my_body"></body></html>');
    ed.close();
    ed.contentEditable = true;
    ed.designMode = 'on';
//////////////////////////////////////////////////////
   // o.contentWindow.onclick=function(){alert('a')}
};function ss(){
if(document.all)
{
var rang = ed.selection.createRange()
rang.pasteHTML(rang.text+"<hr>");
}
else
{
ed.execCommand("insertHTML",false,"<hr>");}
}
</script>
</head>
<BODY>
<input value="aaa" type="button" onClick="ss()">
<IFRAME id="ss" height="200" src="about:blank" width="200" ></IFRAME>
</BODY></HTML>

解决方案 »

  1.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <HTML>
    <head>
    <script>
    var ed = null;
    window.onload = function() {
        var o = document.getElementById("ss"); 
        ed = document.all?o.contentWindow.document:o.contentDocument;
        ed.open();
        ed.write('<html><head><style>html,body{margin:5px;font:14px;word-wrap:break-word}</style></head><body id="my_body"></body></html>');
        ed.close();
        ed.contentEditable = true;
        ed.designMode = 'on';
    };function ss(){
    if(document.all)
    {
    document.getElementById("ss").contentWindow.focus();
        var rang = ed.selection.createRange()
        rang.pasteHTML(rang.text+"<hr>");
    }
    else
    {
        ed.execCommand("insertHTML",false,"<hr>");}
    }
    </script>
    </head>
    <BODY>
    <input value="aaa" type="button" onClick="ss()">
    <IFRAME id="ss" height="200" src="about:blank" width="200" ></IFRAME>
    </BODY></HTML>
      

  2.   

    http://www.quirksmode.org/dom/execCommand/
      

  3.   

    2楼哪个按牛是插入html
    我没发现额!