【问题标题】:Remove table header and body cells using eq使用 eq 删除表格标题和正文单元格
【发布时间】:2017-07-29 02:55:10
【问题描述】:

我正在做一个项目,该表必须动态添加列,如果用户觉得该列未使用,则将其删除。

我的问题是当我删除列标题时,只删除了 tbody 中的一个 td。这是我使用的代码:

$("#tbl thead th:eq("+index+")").remove();
$("#tbl tbody > td:eq("+index+")").remove();

【问题讨论】:

    标签: jquery dynamic indexing html-table


    【解决方案1】:

    试试

    $("#tbl thead th:eq("+index+")").remove();
    $("#tbl tbody tr").find("td:eq("+index+")").remove();
    

    演示:Fiddle

    $("#tbl tr td,th").filter(':nth-child(' + (index + 1) + ')').remove();
    

    演示:Fiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-24
      • 1970-01-01
      • 1970-01-01
      • 2013-08-08
      • 1970-01-01
      • 1970-01-01
      • 2020-03-11
      相关资源
      最近更新 更多