HTML : draw table using innerHTML

前端 未结 2 1085
长情又很酷
长情又很酷 2020-11-27 08:15
document.getElementById(\"outputDiv\").innerHTML = \"\";
document.getElementById(\"outputDiv\").innerHTML += \"\";
for(j=1         
2条回答
  •  失恋的感觉
    2020-11-27 08:59

    I think the main problem is that your attributes are not quoted.

    But it's almost always a bad idea to repeatedly update the content of a dom element in a loop—each time you update dom content it causes some internal work to be done by the browser to make sure the page layout is current.

    I would build the html string up locally, then make one final update when done. (and of course make sure your attributes are quoted)

    document.getElementById("outputDiv").innerHTML = "";
    
    var newTable = "
"; for(j = 1; j <= 10; j++) { //opening braces should always be on the same line in JS newTable += ""; } newTable += "
" + String.fromCharCode(j+64) + "
"; document.getElementById("outputDiv").innerHTML = newTable;

提交回复
热议问题