我有以下 HTML:
<div class="rep_tr0" id="row_2">
只有一个具有此 id 的 div 实例。我怎样才能用 jQuery 删除它?我找到了以下代码,但我不确定如何应用它:
$('.widgets').find(rowId).remove();
最佳答案
获取其ID,然后调用remove。
$('#row_2').remove();
您找到的代码非常相似。这说:
$('.widgets') //find everything with a class of 'widgets'
.find(rowId) //now in all the widgets find something that has 'rowId'
.remove(); //remove it
由于 rowId 在这里是一个变量(没有引号),我不知道你找到它的人的意图是什么。但它需要是 jQuery 可以解析的选择器。就像 id 的 #
或类的 .
一样。
关于jquery - 如何使用 jQuery 删除表中的一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8784077/