我的JavaScript DOM模型存在冲突。我有一个exporttable,一方面生成一个索引号,另一方面导入数据(firsName,lastName和一个importform中的点。我尝试获取第1列的indexnumber,firstName in 2,lastName in 3和point in 4。
此时indexnumber在第1列(好),但firstName也在第1列开始(不好)。如果添加(参见脚本)newRow.insertCell(1);控制台抗议。
谁能帮帮我?
<script>
var button3 = document.getElementById("button2");
button3.onclick= addData;
function addData() {
// collect data firstname, lastname, points
var firstName = document.getElementById("firstname");
var lastName = document.getElementById("lastname");
var Points = document.getElementById("points");
var exportTable = document.getElementById("exportTable");
var newRow = exportTable.insertRow(-1);
var cel1 = newRow.insertCell(0); //I can not start here with insertCell(0);
var cel2 = newRow.insertCell(1);
var cel3 = newRow.insertCell(2);
cel1.innerHTML = firstName.value;
cel2.innerHTML = lastName.value;
cel3.innerHTML = Points.value;
//instal number
var amountRows = exportTable.rows.length;
for (var i = 1; i < amountRows; i++) {
exportTable.rows[i].children[0].innerHTML = i;
}
}
</script>