单击“取消”按钮时,我正在尝试删除模态中的肢体数据。我的代码有效,但删除了包括thead的内容。有人可以指出我的代码有什么问题吗?是否可以仅删除表的正文区域而不是删除整个表内容?
var size = document.getElementById('partnersize').value;
counter = 0;
//alert(size);
for (i = 0; i < size; i++) {
var branchname = document.getElementById('branchname['+i+']').value;
var branchid = document.getElementById('branchid['+i+']').value;
var balance = document.getElementById('balance['+i+']').value;
var amount = document.getElementById('amount['+i+']').value;
if(amount!="")
{
$('#confirmModal').find('.table').append('<tr><td id="branchname'+counter+'">'+branchname+'</td><td id="branchid'+counter+'">'+branchid+'</td><td id="balance'+counter+'">'+balance+'</td><td id="amount'+counter+'">'+amount+'</td></tr>');
counter = counter + 1;
}
}
$('#confirmModal').modal('show');
$('#closeBtn').click(function(){
$('#confirmModal').find('.tbody').html("");
});
<table class="table" id="table"> <!-- table-bordered table-striped-->
<thead>
<tr>
<th id="removetable">
Branch Name
</th>
<th id="removetable">
Branch Id
</th>
<th id="removetable">
Balance
</th>
<th id="removetable">
Amount
</th>
<!-- <th id="removetable">
Status
</th> -->
</tr>
</thead>
<tbody id="tableBody">
<div id="data" style="padding-bottom: 10px; margin-top: 47px; float: right; color:#FF0000;">
</div>
</tbody>
</table>
答案 0 :(得分:0)
您可以使用
$("#TableIDHere tbody").empty();