From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../api/htmltableelement/createcaption/index.html | 26 +++++ .../api/htmltableelement/deletethead/index.html | 63 ++++++++++ files/zh-cn/web/api/htmltableelement/index.html | 130 +++++++++++++++++++++ .../zh-cn/web/api/htmltableelement/rows/index.html | 37 ++++++ 4 files changed, 256 insertions(+) create mode 100644 files/zh-cn/web/api/htmltableelement/createcaption/index.html create mode 100644 files/zh-cn/web/api/htmltableelement/deletethead/index.html create mode 100644 files/zh-cn/web/api/htmltableelement/index.html create mode 100644 files/zh-cn/web/api/htmltableelement/rows/index.html (limited to 'files/zh-cn/web/api/htmltableelement') diff --git a/files/zh-cn/web/api/htmltableelement/createcaption/index.html b/files/zh-cn/web/api/htmltableelement/createcaption/index.html new file mode 100644 index 0000000000..86aa3ab21b --- /dev/null +++ b/files/zh-cn/web/api/htmltableelement/createcaption/index.html @@ -0,0 +1,26 @@ +--- +title: HTMLTableElement.createCaption() +slug: Web/API/HTMLTableElement/createCaption +translation_of: Web/API/HTMLTableElement/createCaption +--- +
+
+
{{APIRef("HTML DOM")}}
+
+
+ +

这个 HTMLTableElement.createCaption() 方法返回这个 table 元素的 caption(HTMLTableCaptionElement). 如果这个 table 没有 caption,这个方法创建并返回 caption.

+ +

语法

+ +
HTMLTableCaptionElement = table.createCaption()
+ +

示例

+ +
mycap = mytable.createCaption();
+ +

Specification

+ + diff --git a/files/zh-cn/web/api/htmltableelement/deletethead/index.html b/files/zh-cn/web/api/htmltableelement/deletethead/index.html new file mode 100644 index 0000000000..bd9b5bf6ef --- /dev/null +++ b/files/zh-cn/web/api/htmltableelement/deletethead/index.html @@ -0,0 +1,63 @@ +--- +title: HTMLTableElement.deleteTHead() +slug: Web/API/HTMLTableElement/deleteTHead +tags: + - API + - table + - 参考 +translation_of: Web/API/HTMLTableElement/deleteTHead +--- +
{{APIRef("HTML DOM")}}
+ +

HTMLTableElement.deleteTHead() 方法删除指定 {{HtmlElement("table")}} 的 {{HTMLElement("thead")}} 元素。

+ +

语法

+ +
HTMLTableElement.deleteTHead();
+
+ +

例子

+ +

本示例使用 JavaScript 删除表格的头部。

+ +

HTML

+ +
<table>
+  <thead><th>Name</th><th>Occupation</th></thead>
+  <tr><td>Bob</td><td>Plumber</td></tr>
+  <tr><td>Jim</td><td>Roofer</td></tr>
+</table>
+ +

JavaScript

+ +
let table = document.querySelector('table');
+table.deleteTHead();
+ +

结果

+ +

{{EmbedLiveSample("Example")}}

+ +

规范

+ + + + + + + + + + + + + + + + +
规范状态备注
{{SpecName('HTML WHATWG', '#dom-table-deletethead', 'HTMLTableElement: deleteTHead')}}{{Spec2('HTML WHATWG')}}
+ +

浏览器兼容性

+ + + +

{{Compat("api.HTMLTableElement.deleteTHead")}}

diff --git a/files/zh-cn/web/api/htmltableelement/index.html b/files/zh-cn/web/api/htmltableelement/index.html new file mode 100644 index 0000000000..a4c1f7ee7e --- /dev/null +++ b/files/zh-cn/web/api/htmltableelement/index.html @@ -0,0 +1,130 @@ +--- +title: HTMLTableElement +slug: Web/API/HTMLTableElement +tags: + - API + - DOM + - Interface + - Reference +translation_of: Web/API/HTMLTableElement +--- +

{{APIRef("HTML DOM")}}

+ +

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

+ +

{{InheritanceDiagram(600, 120)}}

+ +

属性

+ +

继承自父接口,{{DOMxRef("HTMLElement")}}。

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

过时的属性

+ +
+

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

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

方法

+ +

继承自父接口,{{DOMxRef("HTMLElement")}}

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

规范

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
规范状态备注
{{SpecName('HTML WHATWG', "#htmltableelement", "HTMLTableElement")}}{{Spec2('HTML WHATWG')}}添加了 sortable 属性和 stopSorting() 方法。
{{SpecName('HTML5 W3C', "tabular-data.html#the-table-element", "HTMLTableElement")}}{{Spec2('HTML5 W3C')}}添加了 createTBody() 方法。
{{SpecName('DOM2 HTML', 'html.html#ID-64060425', 'HTMLTableElement')}}{{Spec2('DOM2 HTML')}}规定了当 captiontHeadtFootinsertRow()deleteRow() 发生异常时。
{{SpecName('DOM1', 'level-one-html.html#ID-64060425', 'HTMLTableElement')}}{{Spec2('DOM1')}}初始定义。
+ +

浏览器兼容性

+ + + +

{{Compat("api.HTMLTableElement")}}

+ +

另请参阅

+ + diff --git a/files/zh-cn/web/api/htmltableelement/rows/index.html b/files/zh-cn/web/api/htmltableelement/rows/index.html new file mode 100644 index 0000000000..af8619af5e --- /dev/null +++ b/files/zh-cn/web/api/htmltableelement/rows/index.html @@ -0,0 +1,37 @@ +--- +title: HTMLTableElement.rows +slug: Web/API/HTMLTableElement/rows +tags: + - HTML Table Element + - HTMLTableElement.cells + - HTMLTableElement.rows +translation_of: Web/API/HTMLTableElement/rows +--- +
+
+
{{APIRef("HTML DOM")}}
+ +
表中所有行的
+
+
+ +

HTMLTableElement.rows 只读属性返回表中所有行的一个活的 {{domxref("HTMLCollection")}}。HTMLTableElement.rows 包括与之相关的{{HTMLElement("thead")}}, {{HTMLElement("tfoot")}} 和 {{HTMLElement("tbody")}} 元素.

+ +

Although the property is read-only, the returned object is live and allows the modification of its content.

+ +

Syntax

+ +
HTMLCollectionObject = table.rows
+ +

Example

+ +
myrows = mytable.rows;
+firstRow = mytable.rows[0];
+lastRow = mytable.rows[mytable.rows.length-1];
+ +

Specification

+ + -- cgit v1.2.3-54-g00ecf