HTMLTableElement
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
HTMLTableElement
接口在常用的 HTMLElement
接口的基础上,提供了专门的属性和方法来处理 HTML 文档中表格的布局与展示。通过继承,它也可以访问父接口 HTMLElement
中的成员。
属性
继承自父接口,HTMLElement
。
HTMLTableElement.caption
-
这是一个
HTMLTableCaptionElement
,表示作为子元素中的第一个
,如果找不到则为null
。当设置此属性时,如果给出的对象不是一个
,一个带有HierarchyRequestError
名字的异常DOMException
会被抛出。如果设置了正确的对象,它会被作为第一个子元素插入 DOM 树中,同时子元素中的第一个
会被移除,如果存在的话。 HTMLTableElement.tHead
-
这是一个
HTMLTableSectionElement
,表示子元素中的第一个,如果找不到则为
null
。当设置此属性时,如果给出的对象不是一个,一个带有
HierarchyRequestError
名字的异常DOMException
会被抛出。如果设置了正确的对象,它会被立即插入到 DOM 树中既不是
也不是
的第一个元素之前,或者直接被作为最后一个元素插入(如果找不到上述元素的话),同时子元素中的第一个会被移除,如果存在的话。
HTMLTableElement.tFoot
这是一个
HTMLTableSectionElement
,表示子元素中的第一个,如果找不到则为
null
。当设置此属性时,如果给出的对象不是一个,一个带有
HierarchyRequestError
名字的异常DOMException
会被抛出。如果设置了正确的对象,它会被立即插入到 DOM 树中既不是
、
也不是的第一个元素之前,或者直接被作为最后一个元素插入(如果找不到上述元素的话),同时子元素中的第一个
会被移除,如果存在的话。
HTMLTableElement.rows
只读返回一个实时的
HTMLCollection
,它包含元素中的所有行,也就是子元素中的所有,或者是 、
和
三者子元素中的其中一个子元素。
中的行会按照 DOM 树的顺序出现在首位,
中的行出现在末位,也会按照 DOM 树的顺序。
HTMLCollection
对象是实时的,当HTMLTableElement
发生变化时会自动更新。HTMLTableElement.tBodies
只读返回一个实时的
HTMLCollection
,它包含元素中所有的。
HTMLCollection
对象是实时的,当HTMLTableElement
发生变化时会自动更新。过时的属性
警告: 以下属性已经过时,应当避免使用它们。
HTMLTableElement.align
已弃用-
Is a
DOMString
containing an enumerated value reflecting thealign
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 obsoletebgcolor
attribute. HTMLTableElement.border
已弃用-
Is a
DOMString
containing the width in pixels of the border of the table. It reflects the obsoleteborder
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 obsoletecellpadding
attribute. HTMLTableElement.cellSpacing
已弃用-
Is a
DOMString
containing the width in pixels of the horizontal and vertical separation between cells. It reflects the obsoletecellspacing
attribute. HTMLTableElement.frame
已弃用-
Is a
DOMString
containing the type of the external borders of the table. It reflects the obsoleteframe
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 obsoleterules
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 obsoletesummary
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 obsoletewidth
attribute.
方法
继承自父接口,
HTMLElement
。HTMLTableElement.createTHead()
-
返回一个
HTMLElement
,表示子元素中的第一个。如果找不到,则创建一个新的并且立即插入到 DOM 树中既不是
也不是
的第一个元素之前,或者直接被作为最后一个元素插入(如果找不到上述元素的话)。HTMLTableElement.deleteTHead()
移除子元素中的第一个
。
HTMLTableElement.createTFoot()
返回一个
HTMLElement
,表示子元素中的第一个。如果找不到,则创建一个新的并且立即插入到 DOM 树中既不是
、
也不是的第一个元素之前,或者直接被作为最后一个元素插入(如果找不到上述元素的话)。
HTMLTableElement.deleteTFoot()
移除子元素中的第一个
。
HTMLTableElement.createCaption()
返回一个
HTMLElement
,表示子元素中的第一个
。如果找不到,则创建一个新的并且插入到 DOM 树中作为