实例
例子 1
创建 <tfoot> 元素(并在其中插入 <tr> 和 <td> 元素):
// 查找 id="myTable" 的 <table> 元素:
var table = document.getElementById("myTable");
// 创建空的 <tfoot> 元素并将其添加到表中:
var footer = table.createTFoot();
// 创建空的 <tr> 元素并将其添加到 <tfoot> 的第一个位置:
var row = footer.insertRow(0);
// 在 "新的" <tr> 元素的第一个位置插入新单元格 (<td>):
var cell = row.insertCell(0);
// 在新单元格中添加粗体文本:
cell.innerHTML = "<b>This is a table footer</b>";
亲自试一试
例子 2
创建和删除 <tfoot> 元素:
function myCreateFunction() {
var table = document.getElementById("myTable");
var footer = table.createTFoot();
var row = footer.insertRow(0);
var cell = row.insertCell(0);
cell.innerHTML = "<b>This is a table footer</b>";
}
function myDeleteFunction() {
document.getElementById("myTable").deleteTFoot();
}
亲自试一试