HTML DOM Table 對象

Table 對象

Table 對象代表 HTML <table> 元素。

訪問 Table 對象

您可以使用 getElementById() 訪問 <table> 元素:

var x = document.getElementById("myTable");

親自試一試

創建 Table 對象

您可以使用 document.createElement() 方法創建 <table> 元素:

var x = document.createElement("TABLE");

親自試一試

Table 對象集合

集合 描述
cells 返回表中所有 <td> 或 <th> 元素的集合。
rows 返回表中所有 <tr> 元素的集合。
tBodies 返回表中所有 <tbody> 元素的集合。

Table 對象屬性

屬性 描述
align

HTML5 中不支持。請改用 style.cssFloat

設置或返回相對周圍文本的表格對齊方式。

background

HTML5 中不支持。請改用 style.background

設置或返回表格的背景圖片。

bgColor

HTML5 中不支持。請改用 style.backgroundColor

設置或返回表格的背景顏色。

border

已棄用。請改用 style.border

設置或返回表格邊框的寬度。

caption 返回表格的 <caption> 元素。
cellPadding

HTML5 中不支持。請改用 style.padding

設置或返回單元格邊框和單元格內容之間的空間量。

cellSpacing

HTML5 中不支持。請改用 style.borderSpacing

設置或返回表格中單元格之間的空間量。

frame

HTML5 中不支持。

設置或返回應該顯示的(表格的)外邊框。

height

HTML5 中不支持。請改用 style.height

設置或返回表格的高度。

rules

HTML5 中不支持。

設置或返回應在表格中顯示的內邊框(單元格之間)。

summary

HTML5 中不支持。

設置或返回對表中數據的描述。

tFoot 返回對表的 <tfoot> 元素的引用。
tHead 返回對表的 <thead> 元素的引用。
width

HTML5 中不支持。請改用 style.width

設置或返回表格的寬度。

Table 對象方法

方法 描述
createCaption() 創建空的 <caption> 元素并將其添加到表中。
createTFoot() 創建空的 <tfoot> 元素并將其添加到表格中。
createTHead() 創建空的 <thead> 元素并將其添加到表中。
deleteCaption() 從表格中移除第一個 <caption> 元素。
deleteRow() 從表中刪除一行 (<tr>)。
deleteTFoot() 從表格中移除 <tfoot> 元素。
deleteTHead() 從表中移除 <thead> 元素。
insertRow() 創建空的 <tr> 元素并將其添加到表中。

標準屬性和事件

Table 對象同時支持標準屬性事件

相關頁面

HTML 教程:HTML 表格

HTML 參考手冊:HTML <table> 標簽