javascript当中CreateTRTD2的用法

例 2.4(CreateTRTD2IEFF.html)  


<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>

更多参考原文地址:http://www.mark-to-win.com/index.html?content=Javascript/jsUrl.html&chapter=Javascript/js7_web.html#CreateTRTD2IEFF

猜你喜欢

转载自blog.csdn.net/mark_to_win/article/details/88681389
今日推荐