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
支持 支持 支持 支持 支持