删除使用JavaScript的HTML表行
问题描述:
我使用低于code。使用JavaScript来删除HTML表格行,但它给我的错误。
I am using below code to delete HTML Table row using javascript but its giving me error.
使用下面code,我使用的JavaScript,其中包含删除锚标签创建在运行时的一列。
using below code i am creating a column at run time using javascript which contains delete Anchor tag.
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表格的当前行功能:
Below function i am using to delete current row of html table:
function deleteCriteria(i) {
if (window.confirm('Are you sure you want to delete this record?') == true) {
document.getElementById("<%= tblcriteria.ClientID %>").deleteRow(i);
}
}
它给我以下错误:
its giving me below error:
'this.parentNode.parentNode.rowIndex' is null or not an object
请告诉我,我在哪里犯错...
Please tell me where i am making mistake...
答
这个
不指向&LT; A&GT;
元素,但到窗口。
this
does not point to the <a>
element, but to the window.