document.createElement
document.creareAttribute

解决方案 »

  1.   

    <script language="javascript">
    function window.onload()
    { var div = document.createElement("div");
     div.id = "div1";
     div.style.backgroundColor="red";
     div.style.width=200
     div.style.height=200
     div.style.top=10
     div.style.left=10
     div.style.display="block";
     document.body.appendChild(div);
    }
    </script>
      

  2.   

    補充一句﹐document.createElement﹐例子樓上已舉
    document.createAttribute是NN6的方法﹐在IE不能執行﹐以下是例子<body>
    </body>
    <script>
    var e=document.createElement("input")
    var a=document.createAttribute("type")
    a.nodeValue="text"
    e.setAttributeNode(a)
    document.body.appendChild(e)
    </script>
      

  3.   

    to liuzxit(陷入MS...痛并快乐着) & wangxiaomax(缺省值) :
    如果我的页面里有table,如何在特定的td中显示出来呀?body只能是追加到页面最后啊。
    还有,如果我想删除我创建的控件,又该怎么办呀?
      

  4.   

    动态创建TABLE的时候,请注意正确格式为
    <table><tbody><tr><td></td></tr></tbody></table><SCRIPT LANGUAGE="JavaScript">
    tableObj = document.createElement("TABLE");
    tbodyObj = document.createElement("TBODY");
    tr1Obj = document.createElement("TR");
    tr1td1Obj = document.createElement("TD");
    tr1td1Obj.innerText="test"
    returnValue = tableObj.appendChild(tbodyObj);
    tbodyObj.appendChild(tr1Obj);
    tr1Obj.appendChild(tr1td1Obj);
    document.body.appendChild(tableObj);
    </SCRIPT>