HTMLTableElement

HTMLTableElement 接口在常用的 HTMLElement 接口的基础上,提供了专门的属性和方法来处理 HTML 文档中表格的布局与展示。通过继承,它也可以访问父接口 HTMLElement 中的成员。

属性

继承自父接口,HTMLElement

HTMLTableElement.caption
这是一个 HTMLTableCaptionElement ,表示作为子元素中的第一个 <caption> ,如果找不到则为 null。当设置此属性时,如果给出的对象不是一个 <caption>,一个带有 HierarchyRequestError 名字的异常 DOMException 会被抛出。如果设置了正确的对象,它会被作为第一个子元素插入DOM树中,同时子元素中的第一个 <caption> 会被移除,如果存在的话。
HTMLTableElement.tHead
这是一个 HTMLTableSectionElement,表示子元素中的第一个 <thead>,如果找不到则为 null 。当设置此属性时,如果给出的对象不是一个 <thead>, 一个带有 HierarchyRequestError 名字的异常 DOMException 会被抛出。如果设置了正确的对象,它会被立即插入到DOM树中既不是 <caption> 也不是 <colgroup> 的第一个元素之前,或者直接被作为最后一个元素插入(如果找不到上述元素的话),同时子元素中的第一个 <thead> 会被移除,如果存在的话。
HTMLTableElement.tFoot
这是一个 HTMLTableSectionElement, 表示子元素中的第一个 <tfoot>,如果找不到则为 null。当设置此属性时,如果给出的对象不是一个 <tfoot>,一个带有 HierarchyRequestError 名字的异常 DOMException 会被抛出。如果设置了正确的对象,它会被立即插入到DOM树中既不是 <caption><colgroup> 也不是 <thead> 的第一个元素之前,或者直接被作为最后一个元素插入(如果找不到上述元素的话),同时子元素中的第一个 <tfoot> 会被移除,如果存在的话。
HTMLTableElement.rows只读
返回一个实时的 HTMLCollection,它包含元素中的所有行,也就是子元素中的所有 <tr>,或者是 <thead><tbody><tfoot> 三者子元素中的其中一个子元素。<thead> 中的行会按照DOM树的顺序出现在首位,<tbody> 中的行出现在末位,也会按照DOM树的顺序。HTMLCollection 对象是实时的,当 HTMLTableElement 发生变化时会自动更新。
HTMLTableElement.tBodies只读
返回一个实时的 HTMLCollection,它包含元素中所有的 <tbody>HTMLCollection 对象是实时的,当 HTMLTableElement 发生变化时会自动更新。

过时的属性

警告:以下属性已经过时,应当避免使用它们。

HTMLTableElement.align
Is a DOMString containing an enumerated value reflecting the align attribute. It indicates the alignment of the element's contents with respect to the surrounding context. The possible values are "left", "right", and "center".
HTMLTableElement.bgColor
Is a DOMString containing the background color of the cells. It reflects the obsolete bgcolor attribute.
HTMLTableElement.border
Is a DOMString containing the width in pixels of the border of the table. It reflects the obsolete border attribute.
HTMLTableElement.cellPadding
Is a DOMString containing the width in pixels of the horizontal and vertical sapce between cell content and cell borders. It reflects the obsolete cellpadding attribute.
HTMLTableElement.cellSpacing
Is a DOMString containing the width in pixels of the horizontal and vertical separation between cells. It reflects the obsolete cellspacing attribute.
HTMLTableElement.frame
Is a DOMString containing the type of the external borders of the table. It reflects the obsolete frame attribute and can take one of the following values: "void", "above", "below", "hsides", "vsides", "lhs", "rhs", "box", or "border".
HTMLTableElement.rules
Is a DOMString containing the type of the internal borders of the table. It reflects the obsolete rules attribute and can take one of the following values: "none", "groups", "rows", "cols", or "all".
HTMLTableElement.summary
Is a DOMString containing a description of the purpose or the structure of the table. It reflects the obsolete summary attribute.
HTMLTableElement.width
Is a DOMString containing the length in pixels or in percentage of the desired width fo the entire table. It reflects the obsolete width attribute.

方法

继承自父接口,HTMLElement

HTMLTableElement.createTHead()
返回一个 HTMLElement,表示子元素中的第一个 <thead>。如果找不到,则创建一个新的并且立即插入到DOM树中既不是 <caption> 也不是 <colgroup> 的第一个元素之前,或者直接被作为最后一个元素插入(如果找不到上述元素的话)。
HTMLTableElement.deleteTHead()
移除子元素中的第一个 <thead>
HTMLTableElement.createTFoot()
返回一个 HTMLElement,表示子元素中的第一个 <tfoot>。如果找不到,则创建一个新的并且立即插入到DOM树中既不是 <caption><colgroup> 也不是 <thead> 的第一个元素之前,或者直接被作为最后一个元素插入(如果找不到上述元素的话)。
HTMLTableElement.deleteTFoot()
移除子元素中的第一个 <tfoot>
HTMLTableElement.createCaption()
返回一个 HTMLElement,表示子元素中的第一个 <caption>。 如果找不到,则创建一个新的并且插入到DOM树中作为 <table> 的第一个子元素。
HTMLTableElement.deleteCaption()
移除子元素中的第一个 <caption>
HTMLTableElement.insertRow()
返回一个 HTMLTableRowElement,表示表格中的一个新行。它会被立即插入到行集合中给定 index 位置所表示的 <tr> 元素之前。如果有必要一个 <tbody> 会被创建。如果 index 值为 -1, 这个新行会被追加到集合中。如果 index 值小于 -1 或者大于集合中的行总数,一个带有 IndexSizeError 值的异常 DOMException 会发生。
HTMLTableElement.deleteRow()
移除与参数中给定 index 值相关的行。如果 index 值为 -1,最后一行会被移除;如果 index 值小于 -1 或者大于集合中的行总数,一个带有 IndexSizeError 值的异常 DOMException 会发生。

规范

规范 状态 备注
HTML Living Standard
HTMLTableElement
Living Standard 添加了 sortable 属性和 stopSorting() 方法。
HTML5
HTMLTableElement
Recommendation 添加了 createTBody() 方法。
Document Object Model (DOM) Level 2 HTML Specification
HTMLTableElement
Obsolete 规定了当 captiontHeadtFootinsertRow()deleteRow() 发生异常时。
Document Object Model (DOM) Level 1 Specification
HTMLTableElement
Obsolete 初始定义。

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
HTMLTableElementChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
align
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
bgColor
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
border
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
captionChrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
cellPadding
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
cellSpacing
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
createCaptionChrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
createTBodyChrome Full support YesEdge Full support 12Firefox Full support 25IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android ? Firefox Android Full support 25Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
createTFootChrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
createTHeadChrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
deleteCaptionChrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
deleteRowChrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
deleteTFootChrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
deleteTHeadChrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
frame
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
insertRowChrome Full support 4Edge Full support 12Firefox Full support 3
Notes
Full support 3
Notes
Notes Starting with Firefox 20, the index argument has been made optional and defaults to -1 as per HTML specification.
IE Full support 5.5Opera Full support 10Safari Full support 4WebView Android Full support ≤37Chrome Android Full support 18Firefox Android Full support 4
Notes
Full support 4
Notes
Notes Starting with Firefox 20, the index argument has been made optional and defaults to -1 as per HTML specification.
Opera Android Full support 10.1Safari iOS Full support 3.2Samsung Internet Android Full support 1.0
rowsChrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
rules
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
sortable
Experimental
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android ? Firefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android ?
stopSorting
Experimental
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android ? Firefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android ?
summary
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
tBodiesChrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
tFootChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
tHeadChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0
width
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support ≤12.1Safari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support YesOpera Android Full support ≤12.1Safari iOS Full support YesSamsung Internet Android Full support 1.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.

另请参阅

  • 实现了这个接口的HTML元素:<table>