1 回答
TA贡献1780条经验 获得超5个赞
for 循环中应该从 x = 0 开始。这是一个可行的解决方案:
btnSave.onclick = function() {
var table = document.getElementById("table");
var row = table.insertRow(document.getElementById("table").rows.length);
var cellID = row.insertCell(0);
var cellNAME = row.insertCell(1);
var cellAGE = row.insertCell(2);
cellID.innerHTML = " some id ";
cellNAME.innerHTML = " some name ";
cellAGE.innerHTML = " some age ";
}
edit.onclick = function() {
var x;
for (x = 0; x < document.getElementById("table").rows.length; x++) {
document.getElementById("table").rows[x].cells[0].innerHTML = x;
}
}
<button id="btnSave">Save</button>
<button id="edit">edit</button>
<table id="table">
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
</tr>
</table>
添加回答
举报