gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 15:26:12 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com