我想删除表的所有行,除了标题.
$("#<%=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();
这是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>
解决方法
尝试使用这个:
$('#<%=tblDetailFourn.ClientID%> tr').not(function(){ return !!$(this).has('th').length; }).remove();