Create HTML table using Javascript

后端 未结 3 1073
陌清茗
陌清茗 2020-12-13 19:43

My question will ultimately be related to this site:

http://dbtest.net16.net/ethanol-01.html

EDIT: View unencrypted page source code here >>> http://dbtest.n

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 20:14

    The problem is that if you try to write a

    or a or
    tag using JS every time you insert a new tag the browser will try to close it as it will think that there is an error on the code.

    Instead of writing your table line by line, concatenate your table into a variable and insert it once created:

     
    

    If your code is in an external JS file, in HTML create an element with an ID where you want your table to appear:

    And in JS instead of document.write(myTable) use the following code:

    document.getElementById('tablePrint').innerHTML = myTable;
    

    提交回复
    热议问题