使用表名删除jquery中的表行

时间:2015-07-21 21:58:14

标签: javascript jquery datatables html-table

我正在遍历已检查的表行,并且如果某个参数为true,则想要删除当前行但是我到目前为止删除了错误的行。任何帮助赞赏。这就是我所拥有的。

$('input[type=checkbox]').each(function() { 
    if (this.checked == true) {
        var del_id = $(this).closest('tr').attr('data-id');

        $.each(del_arr, function(index, value ) {
            if (value == del_id) {
                $('#spreadsheetstable tr:last').remove();
                console.log('Removing :'+  del_id +' And ' + value);
            }
        });
    }
});

2 个答案:

答案 0 :(得分:0)

这样的事情:

Curl

答案 1 :(得分:0)

如果您正在使用jQuery DataTables,最好使用DataTables API方法row().remove()删除行,而不是直接操作DOM。

$('input[type=checkbox]:checked').each(function() {
   var $tr =  $(this).closest('tr');
   var del_id = $tr.attr('data-id');
   $.each(del_arr, function(index, value ) {
      if (value == del_id){
         $('#spreadsheetstable').DataTable().row($tr).remove().draw(false);

         console.log('Removing :'+  del_id +' And ' + value);
         return false;
      }
   });
});