我正在使用下面的代码使用 javascript 删除 HTML 表行,但它给了我错误。
使用下面的代码,我在运行时使用包含删除 anchor 标记的 JavaScript 创建一个列。
var tbody = document.getElementById("<%= tblcriteria.ClientID %>").getElementsByTagName("TBODY")[0];
var row = document.createElement("TR")
var td4 = document.createElement("TD");
var code = "<a href=\"javascript:deleteCriteria(this.parentNode.parentNode.rowIndex);\">delete</a>";
td4.setAttribute("align", "center");
td4.innerHTML = code;
row.appendChild(td4);
tbody.appendChild(row);
下面的函数我用来删除 html 表格的当前行:
function deleteCriteria(i) {
if (window.confirm('Are you sure you want to delete this record?') == true) {
document.getElementById("<%= tblcriteria.ClientID %>").deleteRow(i);
}
}
它给了我以下错误:
'this.parentNode.parentNode.rowIndex' is null or not an object
请告诉我哪里出错了......
最佳答案
this
不指向<a>
元素,但到窗口。
关于asp.net - 使用 Javascript 删除 HTML 表格行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3082609/