Table createTFoot() 方法
示例
建立 <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>";
自己動手試一試 »
描述
createTFoot() 方法建立一個空的 <tfoot> 元素並將其新增到表格中。
注意:如果表格中已存在 <tfoot> 元素,createTFoot() 方法將返回現有元素,而不會建立新的元素。
注意: <tfoot> 元素內部必須包含一個或多個 <tr> 標籤。
提示: 要從表格中刪除 <tfoot> 元素,請使用 deleteTFoot() 方法。
瀏覽器支援
方法 | |||||
---|---|---|---|---|---|
createTFoot() | 是 | 是 | 是 | 是 | 是 |
語法
tableObject.createTFoot()
引數
無 |
技術詳情
返回值 | 新建立的(或已存在的)<tfoot> 元素 |
---|
更多示例
示例
建立和刪除 <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();
}
自己動手試一試 »
相關頁面
HTML 參考: HTML <tfoot> 標籤
↜ Table 物件