且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否可以根据数据属性删除表格行

更新时间:2023-12-04 14:02:10

您需要传递要为其提供data-attributetr的索引

You need to pass the Index of the tr for which you want the data-attribute from

$('#tableid tr:eq(0)'); // First row in table

$('#tableid tr:eq(1)'); // Second row in table

因为表中可能有多行

var theRowId = $('#tableid tr:eq(1)').attr('data-id'); // Get the Second Row id
$('#tableid tr#'+theRowId).remove();  // Remove the row with id

或者,如果您知道该行的ID,只需执行此操作

OR if you know the ID of the Row.. simply do this

$('#tableid tr[data-id="'+theRowId+'"]').remove();