1、清除的主要代码
$("#tabID tr:not(:first)").html("");
或者:
$("#tabID tr:not(:first)").empty("");
2、注意事项
要注意在table标签处要设置cellspacing=“0”,否则会出现每次清空后出现一些空行的情况
<table id="table1id" cellspacing="0" border="1">
以上是用在table中的,保留表头,现在发现可以直接清楚tbody中所有内容就行
表格html:
<div id="table_div">
<table id="table1id" cellspacing="0" border="0" style="border-collapse: separate;border-spacing: 0px 12px;" >
<thead>
<tr style="width: 100%;height: 60px">
<th style="height: 35px;width: 10%"></th>
<th style="height: 35px;width: 30%;"></th>
<th style="height: 35px;width: 10%;"></th>
<th style="height: 35px;width: 40%;"></th>
</tr>
</thead>
<tbody id="tbody1">
</tbody>
</table>
<%-- <div class="scroll-bar"></div>--%>
</div>
js代码:
$("#tbody1").html("");
本文介绍了两种JavaScript代码实现清除表格内容的方法,分别是使用`html()`和`empty()`,并提醒在`table`标签中设置`cellspacing=0`以避免清空后出现空行。示例代码给出了包含`thead`和`tbody`的表格结构,并提供了清除`tbody`内容的JS代码:`$(#tbody1).html()`。
2058

被折叠的 条评论
为什么被折叠?



