javascript当中CreateTRTD2的用法
例2.4 (CreateTRTD2IEFF.html)
马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。
<style>
#TableOne {
position: absolute;
top: 200;
left: 100;
}
</style>
<script>
function buildTable() {
/*马克-to-win:虽然body只有一个,document.getElementsByTagName("body")会返回一个nodelist,所以必须
取第0个。*/
docBody = document.getElementsByTagName("body").item(0)
bodyQixy = document.body;
alert("docBody===bodyQixy is " + (docBody === bodyQixy));
myTable = document.createElement("TABLE")
myTable.id = "TableOne"
myTable.border = 5
myTableBody = document.createElement("TBODY")
for (i = 0; i < 3; i++) {
row = document.createElement("TR")
for (j = 0; j < 3; j++) {
cell = document.createElement("TD")
cell.style.color = "red"
cell.style.background = "#00ffff"
cell.width = 50
cell.height = 20
textVal = "Cell" + i + "_" + j
textNode = document.createTextNode(textVal)
cell.appendChild(textNode)
row.appendChild(cell)
}
myTableBody.appendChild(row)
}
myTable.appendChild(myTableBody)
bodyQixy.appendChild(myTable)
}
window.onload = buildTable
</script>