How to remove all rows of the table but keep the header

后端 未结 9 1583
轮回少年
轮回少年 2020-12-28 17:23

I want to remove all rows of my table except the header.

This is what I\'ve tried but it always deletes all rows and header:

$(\"#<%=tblDetailFour         


        
相关标签:
9条回答
  • 2020-12-28 17:36

    Try using this:

    $('#<%=tblDetailFourn.ClientID%> tr').not(function(){ return !!$(this).has('th').length; }).remove();
    
    0 讨论(0)
  • 2020-12-28 17:39

    This should work, assuming that you don't have any header elements in tbody.

    $("#<%=tblDetailFourn.ClientID%> tbody tr").remove();
    
    0 讨论(0)
  • 2020-12-28 17:42
    $('#tblDetailFourn > tbody > tr > td').parent('tr').empty();
    
    0 讨论(0)
  • 2020-12-28 17:43

    What about:

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

    jsfiddle

    0 讨论(0)
  • 2020-12-28 17:45

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

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

    What you have should work though.

    0 讨论(0)
  • 2020-12-28 17:53

    if you want to delete all the tbody including the tag then use

    $("#tblDetailFourn tbody").remove();
    

    it will remove all the tr under the tbody as well as tbody.

    0 讨论(0)
提交回复
热议问题