我了解如何获取使用 HTML5 数据属性的表对象 $('#tableid tr').attr('data-id')
的属性。但是,当我尝试根据 data-id 属性删除行时,它似乎不起作用。
当我做这样的事情时:
var theRowId = $('#tableid tr').attr('data-id');
$('#tableid tr#'+theRowId).remove();
没用。应该像处理任何其他属性一样处理 Html 5 数据属性,对吗?
最佳答案
您需要传递您想要的 data-attribute 的 tr 的索引
$('#tableid tr:eq(0)');
//表格第一行
$('#tableid tr:eq(1)');
//表格第二行
因为表格中可能有多行
var theRowId = $('#tableid tr:eq(1)').attr('data-id'); // Get the Second Row id
$('#tableid tr#'+theRowId).remove(); // Remove the row with id
或者如果您知道行的 ID.. 只需执行此操作
$('#tableid tr[data-id="'+theRowId+'"]').remove();
关于jquery - 使用 jquery 删除包含数据属性的 html 5 表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13201134/