如果我有 id="tbl_users"的表并且我有
<tr>
<th>name</th>
<th>username</th>
<th>password</th>
</tr>
下面我附加数据。如何在重新加载用户之前清空表(使用 darta 删除所有行),但不删除使用 的行?我在项目中使用JQuery。
最佳答案
如果您总是先看到标题行,则可以直接跳过它:
$('#tbl_users tr').slice(1).remove();
否则你可以使用has
方法:
$('#tbl_users tr').has('td').remove();
要专门查找没有第 th
标记的行,您可以使用 filter
方法:
$('#tbl_users tr').filter(function() {
return !$(this).has('th');
}).remove();
关于jquery - 删除表中除带有 <th> 标记的行之外的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6407492/