清除表jquery
我有一个用许多行填充的HTML表格 。
我怎样才能从表中删除所有的行?
使用.remove()
$("#yourtableid tr").remove(); 如果你想保留这些数据以备将来使用,那么你可以使用.detach()
 $("#yourtableid tr").detach(); 
如果行是表的孩子,那么你可以使用子select器,而不是后代select器,如
 $("#yourtableid > tr").remove(); 
如果您想清除数据但保留标题:
 $('#myTableId tbody').remove(); 
表格必须以这种方式格式化:
 <table id="myTableId"> <thead> <tr> <th>header1</th><th>header2</th> </tr> </thead> <tbody> <tr> <td>data1</td><td>data2</td> </tr> </tbody> </table> 
稍微比单独去除每一个更快:
 $('#myTable').empty() 
 从技术上来说,这也将消除thead , tfoot和tbody元素。 
我需要这个:
 $('#myTable tbody > tr').remove(); 
它删除除标题外的所有行。
核select:
 $("#yourtableid").html(""); 
 破坏#yourtableid内的#yourtableid 。 小心你的select器,因为它会破坏select器中的任何 HTML! 
 $("#employeeTable td").parent().remove(); 
 这将删除所有tr作为孩子的tr 。 即除标题以外的所有行都将被删除。 
这将删除属于正文的所有行,从而保持标题和正文:
$(“#tableLoanInfos tbody tr”)。remove();
  $('#myTable > tr').remove(); 
有这样一个表(有一个标题和一个正文)
 <table id="myTableId"> <thead> </thead> <tbody> </tbody> </table> 
在#tableId里面删除每一个tr都有一个叫做tbody的父类
 $('#tableId tbody > tr').remove(); 
如果你想添加到你的表格,反之亦然
 $('#tableId tbody').append("<tr><td></td>....</tr>"); 
 <table id="myTable" class="table" cellspacing="0" width="100%"> <thead> <tr> <th>Header 1</th> <th>Header 2</th> <th>Header 3</th> </tr> </thead> <tbody id="tblBody"> </tbody> </table> 
并删除:
 $("#tblBody").empty();