HTMLTableElement

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

属性

继承自父接口,HTMLElement

HTMLTableElement.caption (en-US)

这是一个 HTMLTableCaptionElement (en-US) ,表示作为子元素中的第一个 <caption> ,如果找不到则为 null。当设置此属性时,如果给出的对象不是一个 <caption>,一个带有 HierarchyRequestError 名字的异常 DOMException 会被抛出。如果设置了正确的对象,它会被作为第一个子元素插入 DOM 树中,同时子元素中的第一个 <caption> 会被移除,如果存在的话。

HTMLTableElement.tHead (en-US)

这是一个 HTMLTableSectionElement (en-US),表示子元素中的第一个 <thead>,如果找不到则为 null 。当设置此属性时,如果给出的对象不是一个 <thead>,一个带有 HierarchyRequestError 名字的异常 DOMException 会被抛出。如果设置了正确的对象,它会被立即插入到 DOM 树中既不是 <caption> 也不是 <colgroup> 的第一个元素之前,或者直接被作为最后一个元素插入(如果找不到上述元素的话),同时子元素中的第一个 <thead> 会被移除,如果存在的话。

HTMLTableElement.tFoot (en-US)

这是一个 HTMLTableSectionElement (en-US),表示子元素中的第一个 <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 (en-US)只读

返回一个实时的 HTMLCollection,它包含元素中所有的 <tbody>HTMLCollection 对象是实时的,当 HTMLTableElement 发生变化时会自动更新。

过时的属性

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

HTMLTableElement.align (en-US) 已弃用

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 (en-US) 已弃用

Is a DOMString containing the background color of the cells. It reflects the obsolete bgcolor attribute.

HTMLTableElement.border (en-US) 已弃用

Is a DOMString containing the width in pixels of the border of the table. It reflects the obsolete border attribute.

HTMLTableElement.cellPadding (en-US) 已弃用

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 (en-US) 已弃用

Is a DOMString containing the width in pixels of the horizontal and vertical separation between cells. It reflects the obsolete cellspacing attribute.

HTMLTableElement.frame (en-US) 已弃用

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 (en-US) 已弃用

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 (en-US) 已弃用

Is a DOMString containing a description of the purpose or the structure of the table. It reflects the obsolete summary attribute.

HTMLTableElement.width (en-US) 已弃用

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() (en-US)

返回一个 HTMLElement,表示子元素中的第一个 <thead>。如果找不到,则创建一个新的并且立即插入到 DOM 树中既不是 <caption> 也不是 <colgroup> 的第一个元素之前,或者直接被作为最后一个元素插入(如果找不到上述元素的话)。

HTMLTableElement.deleteTHead()

移除子元素中的第一个 <thead>

HTMLTableElement.createTFoot() (en-US)

返回一个 HTMLElement,表示子元素中的第一个 <tfoot>。如果找不到,则创建一个新的并且立即插入到 DOM 树中既不是 <caption><colgroup> 也不是 <thead> 的第一个元素之前,或者直接被作为最后一个元素插入(如果找不到上述元素的话)。

HTMLTableElement.deleteTFoot() (en-US)

移除子元素中的第一个 <tfoot>

HTMLTableElement.createCaption()

返回一个 HTMLElement,表示子元素中的第一个 <caption>。如果找不到,则创建一个新的并且插入到 DOM 树中作为 <table> 的第一个子元素。

HTMLTableElement.deleteCaption() (en-US)

移除子元素中的第一个 <caption>

HTMLTableElement.insertRow() (en-US)

返回一个 HTMLTableRowElement (en-US),表示表格中的一个新行。它会被立即插入到行集合中给定 index 位置所表示的 <tr> 元素之前。如果有必要一个 <tbody> 会被创建。如果 index 值为 -1,这个新行会被追加到集合中。如果 index 值小于 -1 或者大于集合中的行总数,一个带有 IndexSizeError 值的异常 DOMException 会发生。

HTMLTableElement.deleteRow() (en-US)

移除与参数中给定 index 值相关的行。如果 index 值为 -1,最后一行会被移除;如果 index 值小于 -1 或者大于集合中的行总数,一个带有 IndexSizeError 值的异常 DOMException 会发生。

规范

Specification
HTML Standard
# htmltableelement

浏览器兼容性

BCD tables only load in the browser

参见

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