动态的创建客户端控件[收藏网络]动态的操作客户端控件,现在流行的有2种方法, 例如:在web中有这样一段标记 <div id="TestDIv"></div> 我们可以这样在DIV中创建一个table: var table = window.document.createElement("table"); var row1 = window.document.createElement("tr"); var cell1 = window.document.createElement("td"); var cell1_value = window.document.createTextNode("A test table!"); cell1.appendChild(cell1_value); row1.appendChild(cell1); table.appendChild(row1); window.document.getElementById("TestDiv").appendChild(table); 同理,创建其他控件的时候,只需要注意要创建的标记就可以了,比如要创建select的时候,他就要append option了 在修改的时候,要先wnidow.document.getElementById,然后再搜索要更改的节点, 1. childNodes[x] , 根据序号定位 2.nextSibling, 当前节点的下个节点 3.previousSibling 当前节点的上个节点 4. firstChild 5. lastChild |
|