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
DOMStringcontaining an enumerated value reflecting thealignattribute. 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
DOMStringcontaining the background color of the cells. It reflects the obsoletebgcolorattribute. HTMLTableElement.border(en-US) 已弃用-
Is a
DOMStringcontaining the width in pixels of the border of the table. It reflects the obsoleteborderattribute. HTMLTableElement.cellPadding(en-US) 已弃用-
Is a
DOMStringcontaining the width in pixels of the horizontal and vertical sapce between cell content and cell borders. It reflects the obsoletecellpaddingattribute. HTMLTableElement.cellSpacing(en-US) 已弃用-
Is a
DOMStringcontaining the width in pixels of the horizontal and vertical separation between cells. It reflects the obsoletecellspacingattribute. HTMLTableElement.frame(en-US) 已弃用-
Is a
DOMStringcontaining the type of the external borders of the table. It reflects the obsoleteframeattribute and can take one of the following values:"void","above","below","hsides","vsides","lhs","rhs","box", or"border". HTMLTableElement.rules(en-US) 已弃用-
Is a
DOMStringcontaining the type of the internal borders of the table. It reflects the obsoleterulesattribute and can take one of the following values:"none","groups","rows","cols", or"all". HTMLTableElement.summary(en-US) 已弃用-
Is a
DOMStringcontaining a description of the purpose or the structure of the table. It reflects the obsoletesummaryattribute. HTMLTableElement.width(en-US) 已弃用-
Is a
DOMStringcontaining the length in pixels or in percentage of the desired width fo the entire table. It reflects the obsoletewidthattribute.
方法
继承自父接口,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,表示表格中的一个新行。它会被立即插入到行集合中给定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>。