[英]Remove table row in jquery using table name
我正在遍历已检查的表行,如果某个参数为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);
}
});
}
});
像这样:
$('input[type=checkbox]:checked').each(function() {
var $tr = $(this).closest('tr');
var del_id = $(this).closest('tr').attr('data-id');
$.each(del_arr, function(index, value ) {
if (value == del_id){
$tr.remove();
console.log('Removing :'+ del_id +' And ' + value);
return false;
}
});
})
如果您使用的是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;
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.