HTMLTableElement

HTMLTableElement interface provides special properties and methods (beyond the regular HTMLElement object interface it also has available to it by inheritance) for manipulating the layout and presentation of tables in an HTML document.

特性

Inherits properties from its parent, HTMLElement .

HTMLTableElement.caption
HTMLTableCaptionElement representing the first <caption> that is a child of the element, or null if none is found. When set, if the object doesn't represent a <caption> DOMException with the HierarchyRequestError name is thrown. If a correct object is given, it is inserted in the tree as the first child of this element and the first <caption> that is a child of this element is removed from the tree, if any.
HTMLTableElement.tHead
HTMLTableSectionElement representing the first <thead> that is a child of the element, or null if none is found. When set, if the object doesn't represent a <thead> DOMException with the HierarchyRequestError name is thrown. If a correct object is given, it is inserted in the tree immediately before the first element that is neither a <caption> , nor a <colgroup> , or as the last child if there is no such element, and the first <thead> that is a child of this element is removed from the tree, if any.
HTMLTableElement.tFoot
HTMLTableSectionElement representing the first <tfoot> that is a child of the element, or null if none is found. When set, if the object doesn't represent a <tfoot> DOMException with the HierarchyRequestError name is thrown. If a correct object is given, it is inserted in the tree immediately before the first element that is neither a <caption> <colgroup> , nor a <thead> , or as the last child if there is no such element, and the first <tfoot> that is a child of this element is removed from the tree, if any.
HTMLTableElement.rows 只读
Returns a live HTMLCollection containing all the rows of the element, that is all <tr> that are a child of the element, or a child of one of its <thead> , <tbody> and <tfoot> children. The rows members of a <thead> appear first, in tree order, and those members of a <tbody> last, also in tree order. The HTMLCollection is live and is automatically updated when the HTMLTableElement 改变。
HTMLTableElement.tBodies 只读
Returns a live HTMLCollection containing all the <tbody> of the element. The HTMLCollection is live and is automatically updated when the HTMLTableElement 改变。

Obsolete Properties

警告: The following properties are obsolete.  You should avoid using them.

HTMLTableElement.align
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" ,和 "center" .
HTMLTableElement.bgColor
DOMString containing the background color of the cells. It reflects the obsolete bgcolor 属性。
HTMLTableElement.border
DOMString containing the width in pixels of the border of the table. It reflects the obsolete border 属性。
HTMLTableElement.cellPadding
DOMString containing the width in pixels of the horizontal and vertical sapce between cell content and cell borders. It reflects the obsolete cellpadding 属性。
HTMLTableElement.cellSpacing
DOMString containing the width in pixels of the horizontal and vertical separation between cells. It reflects the obsolete cellspacing 属性。
HTMLTableElement.frame
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" ,或 "border" .
HTMLTableElement.rules
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" ,或 "all" .
HTMLTableElement.summary
DOMString containing a description of the purpose or the structure of the table. It reflects the obsolete summary 属性。
HTMLTableElement.width
DOMString containing the length in pixels or in percentage of the desired width fo the entire table. It reflects the obsolete width 属性。

方法

Inherits methods from its parent, HTMLElement .

HTMLTableElement.createTHead()
Returns an HTMLElement representing the first <thead> that is a child of the element. If none is found, a new one is created and inserted in the tree immediately before the first element that is neither a <caption> , nor a <colgroup> , or as the last child if there is no such element.
HTMLTableElement.deleteTHead()
Removes the first <thead> that is a child of the element.
HTMLTableElement.createTFoot()
Returns an HTMLElement representing the first <tfoot> that is a child of the element. If none is found, a new one is created and inserted in the tree immediately before the first element that is neither a <caption> <colgroup> , nor a <thead> , or as the last child if there is no such element.
HTMLTableElement.deleteTFoot()
Removes the first <tfoot> that is a child of the element.
HTMLTableElement.createCaption()
Returns an HTMLElement representing the first <caption> that is a child of the element. If none is found, a new one is created and inserted in the tree as the first child of the <table> 元素。
HTMLTableElement.deleteCaption()
Removes the first <caption> that is a child of the element.
HTMLTableElement.insertRow()
Returns an HTMLTableRowElement representing a new row of the table. It inserts it in the rows collection immediately before the <tr> element at the given index position. If necessary a <tbody> is created. If the index is -1 , the new row is appended to the collection. If the index 小于 -1 or greater than the number of rows in the collection, a DOMException 采用值 IndexSizeError 被引发。
HTMLTableElement.deleteRow()
Removes the row corresponding to the index given in parameter. If the index value is -1 the last row is removed; if it smaller than -1 or greater than the amount of rows in the collection, a DOMException 采用值 IndexSizeError 被引发。

规范

规范 状态 Comment
HTML Living Standard
The definition of 'HTMLTableElement' in that specification.
实时标准 添加 sortable property and the stopSorting() 方法。
HTML5
The definition of 'HTMLTableElement' in that specification.
Recommendation 添加 createTBody() 方法。
Document Object Model (DOM) Level 2 HTML Specification
The definition of 'HTMLTableElement' in that specification.
Obsolete Defined when caption , tHead , tFoot , insertRow() ,和 deleteRow() raise exceptions.
Document Object Model (DOM) Level 1 Specification
The definition of 'HTMLTableElement' in that specification.
Obsolete 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
HTMLTableElement Chrome Yes Edge 12 Firefox 1 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android ?
align
弃用
Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
bgColor
弃用
Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
border
弃用
Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
caption Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
cellPadding
弃用
Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
cellSpacing
弃用
Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
createCaption Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
createTBody Chrome Yes Edge 12 Firefox 25 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android 25 Opera Android Yes Safari iOS Yes Samsung Internet Android ?
createTFoot Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
createTHead Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
deleteCaption Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
deleteRow Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
deleteTFoot Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
deleteTHead Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
frame
弃用
Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
insertRow Chrome 4 Edge 12 Firefox 3
3
Starting with Firefox 20, the index argument has been made optional and defaults to -1 as per HTML specification.
IE 5.5 Opera 10 Safari 4 WebView Android ≤37 Chrome Android 18 Firefox Android 4
4
Starting with Firefox 20, the index argument has been made optional and defaults to -1 as per HTML specification.
Opera Android 10.1 Safari iOS 3.2 Samsung Internet Android 1.0
rows Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
rules
弃用
Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
sortable
Chrome No Edge No Firefox No IE No Opera No Safari No WebView Android No Chrome Android ? Firefox Android No Opera Android No Safari iOS No Samsung Internet Android ?
stopSorting
Chrome No Edge No Firefox No IE No Opera No Safari No WebView Android No Chrome Android ? Firefox Android No Opera Android No Safari iOS No Samsung Internet Android ?
summary
弃用
Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
tBodies Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?
tFoot Chrome Yes Edge 12 Firefox 1 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android ?
tHead Chrome Yes Edge 12 Firefox 1 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android ?
width
弃用
Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android ? Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android ?

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知
实验。期望将来行为有所改变。
实验。期望将来行为有所改变。
弃用。不要用于新网站。
弃用。不要用于新网站。
见实现注意事项。

另请参阅

  • The HTML element implementing this interface: <table> .
  1. HTMLTableElement
  2. 特性
    1. align
    2. bgColor
    3. border
    4. caption
    5. cellPadding
    6. cellSpacing
    7. frame
    8. rows
    9. rules
    10. summary
    11. tBodies
    12. tFoot
    13. tHead
    14. width
  3. 方法
    1. createCaption()
    2. createTFoot()
    3. createTHead()
    4. deleteCaption()
    5. deleteRow()
    6. deleteTFoot()
    7. deleteTHead()
    8. insertRow()
  4. 继承:
    1. HTMLElement
    2. Element
    3. Node
    4. EventTarget
  5. Related pages for HTML DOM
    1. BeforeUnloadEvent
    2. DOMStringMap
    3. ErrorEvent
    4. GlobalEventHandlers
    5. HTMLAnchorElement
    6. HTMLAreaElement
    7. HTMLAudioElement
    8. HTMLBRElement
    9. HTMLBaseElement
    10. HTMLBaseFontElement
    11. HTMLBodyElement
    12. HTMLButtonElement
    13. HTMLCanvasElement
    14. HTMLContentElement
    15. HTMLDListElement
    16. HTMLDataElement
    17. HTMLDataListElement
    18. HTMLDialogElement
    19. HTMLDivElement
    20. HTMLDocument
    21. HTMLElement
    22. HTMLEmbedElement
    23. HTMLFieldSetElement
    24. HTMLFormControlsCollection
    25. HTMLFormElement
    26. HTMLFrameSetElement
    27. HTMLHRElement
    28. HTMLHeadElement
    29. HTMLHeadingElement
    30. HTMLHtmlElement
    31. HTMLIFrameElement
    32. HTMLImageElement
    33. HTMLInputElement
    34. HTMLIsIndexElement
    35. HTMLKeygenElement
    36. HTMLLIElement
    37. HTMLLabelElement
    38. HTMLLegendElement
    39. HTMLLinkElement
    40. HTMLMapElement
    41. HTMLMediaElement
    42. HTMLMetaElement
    43. HTMLMeterElement
    44. HTMLModElement
    45. HTMLOListElement
    46. HTMLObjectElement
    47. HTMLOptGroupElement
    48. HTMLOptionElement
    49. HTMLOptionsCollection
    50. HTMLOutputElement
    51. HTMLParagraphElement
    52. HTMLParamElement
    53. HTMLPictureElement
    54. HTMLPreElement
    55. HTMLProgressElement
    56. HTMLQuoteElement
    57. HTMLScriptElement
    58. HTMLSelectElement
    59. HTMLShadowElement
    60. HTMLSourceElement
    61. HTMLSpanElement
    62. HTMLStyleElement
    63. HTMLTableCaptionElement
    64. HTMLTableCellElement
    65. HTMLTableColElement
    66. HTMLTableDataCellElement
    67. HTMLTableHeaderCellElement
    68. HTMLTableRowElement
    69. HTMLTableSectionElement
    70. HTMLTemplateElement
    71. HTMLTextAreaElement
    72. HTMLTimeElement
    73. HTMLTitleElement
    74. HTMLTrackElement
    75. HTMLUListElement
    76. HTMLUnknownElement
    77. HTMLVideoElement
    78. HashChangeEvent
    79. History
    80. ImageData
    81. Location
    82. MessageChannel
    83. MessageEvent
    84. MessagePort
    85. Navigator
    86. NavigatorGeolocation
    87. NavigatorID
    88. NavigatorLanguage
    89. NavigatorOnLine
    90. NavigatorPlugins
    91. PageTransitionEvent
    92. Plugin
    93. PluginArray
    94. PopStateEvent
    95. PortCollection
    96. PromiseRejectionEvent
    97. RadioNodeList
    98. Transferable
    99. ValidityState
    100. Window
    101. WindowBase64
    102. WindowEventHandlers
    103. WindowTimers