jquery - 使用 jquery 删除包含数据属性的 html 5 表行

标签 jquery html

我了解如何获取使用 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/

相关文章:

html - Bootstrap : center the title on the navbar and move logout button right

jquery - 如果 <a> 有标题,addClass jQuery?

javascript - 检查 pickadate.js datepicker 选择的今天是否不起作用?

javascript - 如何获取在 ddSlick 下拉列表中选择的值

javascript - 在 foreach 中选择特定的单选项目

javascript - jQuery UI 可拖动不会回到第一点

javascript - div 内的弹跳球

javascript - 如何选择wysihtml5编辑器的iframe?

html - 画廊在 HTML5 中应该是什么元素?

html - 中心导航栏内容/链接