删除使用JavaScript的HTML表行 [英] Delete HTML Table Row using Javascript

查看:142
本文介绍了删除使用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.

这篇关于删除使用JavaScript的HTML表行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆