javascript:.innerHTML到表中没有添加新行

时间:2015-10-13 12:41:11

标签: javascript jquery html html-table

我的js没有在表格的末尾添加行 HTML:

<table border="1" style="border-collapse: collapse;" width="100%" id="tbLIFE">
    <tr><th colspan="3">LifePath</th></tr>
    <tr><th colspan="3">Style</th></tr>
    <tr id="LifeEvents"></tr>
</table>

JS:

//LIFE EVENTS
var d61 = Math.floor(Math.random()*6)+1;
var d62 = Math.floor(Math.random()*6)+1;
var Age = d61+d62+16;

document.getElementById("LifeEvents").innerHTML = "<th colspan=3 id='lifeEvents'>Life Events</th>";
document.getElementById("LifeEvents").innerHTML += "</tr><tr><td>Age</td><td>"+Age+"</td>";

我不介意使用jquery。

1 个答案:

答案 0 :(得分:0)

由@Guruprasad Rao提供

var d61 = Math.floor(Math.random()*6)+1;
var d62 = Math.floor(Math.random()*6)+1;
var Age = d61+d62+16;

document.getElementById("LifeEvents").innerHTML = "<th colspan=3 id='lifeEvents'>Life Events</th>";
document.getElementById("tbLIFE").innerHTML += "<tr><td>Age</td><td>"+Age+"</td>";