如何将tr元素附加到表中?

时间:2019-03-04 18:26:58

标签: javascript

我试图将tr附加到表中,而2个td元素已经附加到我的tr元素中。这是我使用的代码:

var month = 2;
var save = 0;
setInterval(function() { 
month += 1; 
alert("It is the next month."); 
save = 0;
var tr = document.createElement("TR");
var td1 = document.createElement("TD");
var txt1 = document.createTextNode(month);
var td2 = document.createElement("TD");
var txt2 = document.createTextNode("$" + save);
var table = document.getElementById(table1);
td1.appendChild(txt1);
td2.appendChild(txt2);
tr.appendChild(td1);
tr.appendChild(td2);
table.appendChild(tr);
document.getElementById("howMuchSavings").innerHTML = "$0"
}, 30000);
function saveMore() {
save += 1;
document.getElementById("howMuchSavings").innerHTML = "$" + save;
}

0 个答案:

没有答案