[removed] AppendChild

后端 未结 6 1004
花落未央
花落未央 2020-12-10 07:10

I was learning about appendChild and have so far come up with this code:

6条回答
  •  孤街浪徒
    2020-12-10 07:19

    Try wrapping your JavaScript in an onload function. So first add:

    
    

    Then put your javascript in the load function, so:

    function load() {
        var blah="Blah!";
        var t  = document.createElement("table"),
        tb = document.createElement("tbody"),
        tr = document.createElement("tr"),
        td = document.createElement("td");
    
        t.style.width = "100%";
        t.style.borderCollapse = 'collapse';
    
        td.appendChild(document.createTextNode(blah)); 
    
        // note the reverse order of adding child        
        tr.appendChild(td);
        tb.appendChild(tr);
        t.appendChild(tb);
    
       document.getElementById("theBlah").appendChild(t);
    }
    

提交回复
热议问题