Javascript 如何删除表中的td
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31468519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove td in table
提问by Lam Son
How can I remove a td
cell in a table with MVC4?
如何td
使用MVC4删除表格中的单元格?
Could I use JQuery or JavaScript? And if so, how?
我可以使用 JQuery 或 JavaScript 吗?如果是这样,如何?
<table class="table table-striped table-bordered table-hover" id="tblParticipantList">
<thead>
<tr>
<th>Name</th>
<th>Adress</th>
<th>Redeem Code</th>
</tr>
</thead>
<tbody>
<tr data-id="columnId" id="customerPartial_94">
<td data-field="NAME">Attn Donna</td>
<td data-field="ADDRESS">3046 Lavon Drive Newyork America 7504</td>
<td data-field="SECURITY_REDEMPTION_CD"></td>
</tr>
<tr data-id="columnId" id="customerPartial_95">
<td data-field="NAME">F 1 La 1</td>
<td data-field="ADDRESS">Asd 1 s 1 Ci 1 s</td>
<td data-field="SECURITY_REDEMPTION_CD"></td>
</tr>
</tbody>
</table>
回答by Luc
To remove TD item, you should know exactly td what you want to remove.
要删除 TD 项目,您应该确切地知道要删除的内容。
Remove All TD item
$('#tblParticipantList > tr > td').remove();
Remove TD at specified Row
$('#tblParticipantList > tr').eq(rowNum).children('td').remove();
Remove TD at specified Row and Column
$('#tblParticipantList > tr').eq(rowNum).children('td').eq(colNum).remove();
删除所有 TD 项目
$('#tblParticipantList > tr > td').remove();
删除指定行的 TD
$('#tblParticipantList > tr').eq(rowNum).children('td').remove();
删除指定行和列的 TD
$('#tblParticipantList > tr').eq(rowNum).children('td').eq(colNum).remove();
回答by RRK
Remove child td
of the position you want using eq()
. Use proper id and class in the selector for expected result.
使用 删除td
您想要的位置的子级eq()
。在选择器中使用正确的 id 和 class 以获得预期结果。
$('.table-striped tr').each(function(){
$(this).children('td').eq(3).remove();
});