如何删除表的所有行但保留标题

Mar*_*arc 17 asp.net jquery html-table

我想删除除了标题之外的所有表格行.

这是我尝试过但它总是删除所有行和标题:

$("#<%=tblDetailFourn.ClientID%> tbody tr").remove();

$("#<%=tblDetailFourn.ClientID%> tbody tr").not("thead tr").remove();

$("#<%=tblDetailFourn.ClientID%> tr").not("thead tr").remove();

$("#<%=tblDetailFourn.ClientID%> tbody").not("thead").remove();

$("#<%=tblDetailFourn.ClientID%> tbody").remove();

$("#<%=tblDetailFourn.ClientID%> > tbody").remove();
Run Code Online (Sandbox Code Playgroud)

这是html:

<table id="tblDetailFourn" runat="server" class="ProjetTable ProjetTableHover">
    <thead>
       <tr>
          <th style="width:200px">Rôle de Ressource</th>
          <th style="width:200px">Nom Prénom</th>
          <th style="width:120px">Tel</th>
          <th style="width:200px">Courriel</th>
          <th style="width:80px">Actif</th>
          <th style="width:33px"></th>
          <th style="width:33px"></th>
      </tr>
    </thead>
    <tbody>
    </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

Geo*_*org 47

$('#tblDetailFourn tbody').empty();
Run Code Online (Sandbox Code Playgroud)


Bri*_*ins 11

试试http://api.jquery.com/child-selector/

$("#<%=tblDetailFourn.ClientID%> > tbody > tr").remove();
Run Code Online (Sandbox Code Playgroud)

你有什么应该工作.


Lik*_*d_T 11

试试这个:

$('#<%=tblDetailFourn.ClientID%> tr').not(function(){ return !!$(this).has('th').length; }).remove();
Run Code Online (Sandbox Code Playgroud)


小智 5

关于什么:

$('#tblDetailFourn tbody').html('');

jsfiddle