我有这个代码:
var table = document.getElementById("editTable");
var row = table.insertRow(-1);
var i = row.rowIndex;
var remove = document.createElement("input");
remove.type = "button";
remove.value = "Remove";
remove.onclick = (function() {
var I = i;
return function() {
table.deleteRow(I);
}
})();
var td1 = row.insertCell(-1);
td1.appendChild(remove);
我在这里阅读了几篇文章,但我不明白我做错了什么。当我尝试删除我创建的最后一行时,我收到此错误:
IndexSizeError: Index or size is negative or greater than the allowed amount
table.deleteRow(I);
我很确定这是一个关闭问题。我了解 javascript 中匿名函数的范围但不了解语法;