document.write("<html>...</html>");这种方法动态生成的html代码是不是不能再DOm树上取到要用
var test=document.createElement("XXX");document.getElementByID("yy").Append(test);
才能在dom树上取得到,这部分知识点在网上和书上找不到再有两者有什么详细区别

解决方案 »

  1.   

    要给动态生成的html代码 绑定事件 怎么绑定 什么时候绑定
      

  2.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title>
    <script></script>
    </head><body>
    <script>
    document.write("<input type='text' id='txt' onclick='alert(111)' style='width:200px' value=''/>");
    var t1 = document.createElement("input");
    t1.id = "t1";
    t1.style.width = "300px";
    t1.onclick=function(){alert("document.createElement加进来的");};//绑定事件
    document.body.appendChild(t1);document.getElementById("txt").value="document.write加进来的";
    document.getElementById("t1").value="document.createElement加进来的";
    </script>
    </body></html>
      

  3.   


    function test(){
        alert("test")
    }
    document.write("<html><body onclick="test()">...</html>");
    就写在html中和平时一样就可以了,但是这写调用函数一定要写在动态加载之前,防止不必要的错误,