我有一个带有页眉和页脚的 HTML 表格:
<table id="myTable">
<thead>
<tr>
<th>My Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>aaaaa</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>My footer</td>
</tr>
<tfoot>
</table>
我正在尝试在 tbody
添加一行,内容如下:
myTable.insertRow(myTable.rows.length - 1);
但该行已添加到 tfoot
部分。
如何插入 tbody
?
原文由 Jérôme Verstrynge 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果要在
tbody
中添加一行,请获取对它的引用并调用其insertRow
方法。(JSFiddle 上的旧 演示)