如何从填充表中删除表行(第1行除外)?

时间:2010-08-18 16:16:27

标签: jquery

我有一个表格可以返回搜索结果。当用户搜索其他内容时,存在相同的结果,表只是填充数据而不删除先前的搜索。这都是JSON结果操作,没有回发,因此页面不会重新加载。刷新页面时,我得到一个空表。我尝试使用以下代码。

$('searchTable').find("tr:gt(0)").remove();
$('searchTable').children('tr:not(:first)').remove();
$('searchTable td').parent().remove();

在下表中

<table id="searchTable">
    <tr>
        <th>Name</th>
        <th>Address</th>
        <th>IdNumber</th>
        <th>Status</th>
        <th>Date</th>
    </tr>        
    <tr>
        <td class="name"></td>
        <td class="address"></td>
        <td class="idNum"></td>
        <td class="status"></td>
        <td class="date"></td>
    </tr>
</table>

如何在转到JSON响应之前删除以前的搜索结果?

1 个答案:

答案 0 :(得分:3)

您错过了#ID selector中的#,如下所示:

$('#searchTable tr:gt(0)').remove();

You can try it out here,没有#它是element selector,它正在寻找<searchTable>元素。

相关问题