最好的方法,兼容Mozilla<input type=button value=add onclick=add()>
<script>
function add()
{
var s = "啊哈哈"
n = document.createTextNode(s)
document.getElementById("x").appendChild(n)
}
</script>
<div id=x></div>
其他

解决方案 »

  1.   

    要支持html,可以这样<input type=button value=add onclick=add()>
    <script>
    function add()
    {
    var s = "啊哈哈<img src='http://www.mozilla.org/images/mlogo.gif'>"
    n = document.createElement("SPAN")
    n.innerHTML = s
    document.getElementById("x").appendChild(n)
    }
    </script>
    <div id=x></div>
    其他
      

  2.   

    谢谢!我马上测试一下。感觉目前对html,js的思路局限于静态dom操作,有没有比较好的资料可以推荐一下?
      

  3.   

    http://www.mozilla.org/docs/dom/domref/dom_shortIX.htmlhttp://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/dhtml_reference_entry.asp
      

  4.   

    发现mozilla/ie的一点细微不同,m可以把不同父子层次的document.element互相操作,比如
    parent.appendchild(childnode),ie就不行,必须位于同一窗口层次才可以,否则会显示parent找不到.
      

  5.   

    实际测试了一下,运行几个小时后似乎占用系统资源更多,innerHTML+= 还能看到内容更新,只是每次闪动一次,createElement方式下浏览器就进入停止响应状态了...