我需要删除行,请帮帮我 [英] I need to delete the rows please help me

查看:72
本文介绍了我需要删除行,请帮帮我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生您好,

我制作了一个动态行生成的表,可以在其中生成表,但无法删除它,为此,我使用了javascript代码,代码如下所示:

我已经用调试器编写了代码;因为我对此进行了调试,所以请指导我不要计算我使用的调试器代码

Hello sir,

I made one dyanmic rows generated table in which I m able to generate the table, but unable to delete it, I m using javascript code for this the code is shown below:

I have written the code with debugger; because I debug this so guide me not counting debugger code I used

<Script type="text/javascript">
function deleteRow(tblPartner) {
            debugger;
            try {
                var table = document.getElementById(tblPartner);
                var rowCount = table.rows.length;
                for (var i = 0; i < rowCount; i++) {
                    var row = table.rows[i];
                    var chkBox = row.cells[0].childNodes[0];
                    if (null != chkBox && true == chkBox.checked) {
                        if (rowCount <=1) {
                            alert("Cannot delete all the rows.");
                            break;
                        }
                        table.deleteRow(i);
                        rowCount--;
                        i--;
                    }
                }
            } catch (e) {
                alert(e);
            }
</Script>


我的表ID是tblpartner
我正在使用HTML按钮标记来删除<input type="Button" runat="server" Value="Remove" önclick="deleteRow(''tblPartner'')"/>,它不是通过使用表null的值来逐行删除行.
告诉我应该使用ArrayList在第一行上删除

请指导我


my table id is tblpartner
I m using Html button tag to delete <input type="Button" runat="server" Value="Remove" önclick="deleteRow(''tblPartner'')"/> it is not deleting rows on by one taking the value of table null
tell me that I should use ArrayList to delete on row one by one

Please Guide me

推荐答案

在.Net中,每个ID都会在执行时发生变化,同样,它将在每个ID前面添加一个前缀. .....您可以通过
In .Net every id''s changed when it will executed, for the same it will add a prefix to every id''s............You can check it by
Ctrl+U

进行检查并根据其进行更改.之后,它将正常工作……

and change it according that. after that it will worked fine......


您是否要删除除一行以外的所有行?如果是这样,那么对我来说很好.如果要删除所有选定的行,即使它清除了表,也需要更改

Are you trying to delete all but one row? If so, then it''s working fine for me. If you want to delete ALL of the selected rows, even if it clears the table, you need to change

if (rowCount <=1) {







to

if (rowCount <=0) {



因为如果表仅剩1行,则可以防止它们删除最后一行.

在我用来测试代码段的简单HTML文件中,它可以正常工作:



because you are preventing them from deleting the last row if the table only has 1 row left.

It works fine in my simple HTML file I used to test your snippet:

<html>
<head>
<Script type="text/javascript">
function deleteRow(tblPartner) {
   debugger;
   try {
       var table = document.getElementById(tblPartner);
       var rowCount = table.rows.length;
       for (var i = 0; i < rowCount; i++) {
           var row = table.rows[i];
           var chkBox = row.cells[0].childNodes[0];
           if (null != chkBox && true == chkBox.checked) {
               if (rowCount <=0) {
                   alert("Cannot delete all the rows.");
                   break;
               }
               table.deleteRow(i);
               rowCount--;
               i--;
           }
       }
   } catch (e) {
       alert(e);
   }
}
</Script>
</head>
<body>
<table border="1" id="tblPartner">
<tr>
<td><input type="checkbox" />1-1</td>
<td>1-2</td>
<td>1-3</td>
</tr>
<tr>
<td><input type="checkbox" />2-1</td>
<td>2-2</td>
<td>2-3</td>
</tr>
<tr>
<td><input type="checkbox" />3-1</td>
<td>3-2</td>
<td>3-3</td>
</tr>
</table>
<input type="Button"  runat="server" Value="Remove"  önclick="deleteRow('tblPartner')"/>
</body>
</html>


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

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