参考如下代码:
<div style="height:300px; width:600px; border:1px solid #000000">
<iframe id="HtmlEditor" src="" frameborder="0" marginheight="0" marginwidth="0" style="width:100%; height:100%;">d</iframe>
<br><br>
</div>
<script type="text/javascript">
window.onload = function () {
var f = document.getElementById("HtmlEditor");
var html = '<HEAD></HEAD><BODY><div></div></BODY>';
f.contentWindow.document.open("text/html", "replace");
f.contentWindow.document.write(html);
f.contentWindow.document.close();
f.contentWindow.document.designMode = "on";
}
</script>

解决方案 »

  1.   


    <div style="height:300px; width:600px; border:1px solid #000000">
    <iframe id="HtmlEditor" src="" frameborder="0" marginheight="0" marginwidth="0" style="width:100%; height:100%;"></iframe>
    <br><br>
    </div>
    <script type="text/javascript">
    window.onload = function () {
        var f = document.getElementById("HtmlEditor");
        var html = '<HEAD></HEAD><BODY><div></div></BODY>';
        f.contentWindow.document.open("text/html", "replace");
        f.contentWindow.document.write(html);
        f.contentWindow.document.close();
        f.contentWindow.document.body.contentEditable=true;
    }
    </script>
      

  2.   

    麻烦大家能帮我解释解释这三个方法都是干什么的吗?谢谢!
    contentWindow
    contentEditable
    designMode