是否可以根据数据属性删除表格行 [英] is it possible to remove a Table row based on the data attribute
本文介绍了是否可以根据数据属性删除表格行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在单击删除按钮时,是否可以根据数据属性删除表行?
On Click of delete button is it possible to remove the table row based on the data attribute ?
这是我的js代码
$(document).on("click", ".deletevideo", function(event) {
if (confirm("Are You Sure to Remove This Video From This PAC?") == true) {
var video_id = $(this).data('videoid');
}
event.stopImmediatePropagation();
event.preventDefault();
return false;
});
推荐答案
您需要传递要为其提供data-attribute
的tr
的索引
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();
这篇关于是否可以根据数据属性删除表格行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文