Table createTFoot() 方法
定义和用法
createTFoot() 方法创建空的 <tfoot> 元素 并将其添加到表中。
注释:如果表中已经存在 <tfoot> 元素,则 createTFoot() 方法返回现有元素,而不创建新元素。
注释:<tfoot> 元素内部必须有一个或多个 <tr> 标签。
提示:如需从表中删除 <tfoot> 元素,请使用 deleteTFoot() 方法。
另请参阅:
HTML 参考手册:HTML <tfoot> 标签
实例
例子 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();
}
语法
tableObject.createTFoot()
参数
无。
技术细节
| 返回值: | 新创建的(或现有的)<tfoot> 元素。 |
|---|
浏览器支持
| Chrome | Edge | Firefox | Safari | Opera |
|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Opera |
| 支持 | 支持 | 支持 | 支持 | 支持 |