From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- .../web/api/htmltableelement/insertrow/index.html | 154 +++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 files/ru/web/api/htmltableelement/insertrow/index.html (limited to 'files/ru/web/api/htmltableelement/insertrow') diff --git a/files/ru/web/api/htmltableelement/insertrow/index.html b/files/ru/web/api/htmltableelement/insertrow/index.html new file mode 100644 index 0000000000..ea8d0f16aa --- /dev/null +++ b/files/ru/web/api/htmltableelement/insertrow/index.html @@ -0,0 +1,154 @@ +--- +title: HTMLTableElement.insertRow() +slug: Web/API/HTMLTableElement/insertRow +tags: + - API + - HTML DOM + - HTMLTableElement + - Method + - Reference +translation_of: Web/API/HTMLTableElement/insertRow +--- +
+
+
{{APIRef("HTML DOM")}}
+
+
+ +

Метод HTMLTableElement.insertRow()добавляет новую строку в таблицу и возвращает на неё ссылку.

+ +

Синтаксис

+ +
var row = HTMLTableElement.insertRow(optional index = -1);
+ + + +

Пример

+ +
<table id="TableA">
+<tr>
+<td>Old top row</td>
+</tr>
+</table>
+<script type="text/javascript">
+
+function addRow(tableID) {
+  // Get a reference to the table
+  var tableRef = document.getElementById(tableID);
+
+  // Insert a row in the table at row index 0
+  var newRow = tableRef.insertRow(0);
+
+  // Insert a cell in the row at index 0
+  var newCell = newRow.insertCell(0);
+
+  // Append a text node to the cell
+  var newText = document.createTextNode('New top row');
+  newCell.appendChild(newText);
+}
+
+// Call addRow() with the ID of a table
+addRow('TableA');
+
+</script>
+ +

Чтобы быть валидным HTML документом, элемент TR должен содержать хотя бы один TD элемент.

+ +

Обратите внимание, что insertRow добавляет строку непосредственно в таблицу и возвращает ссылку на эту строку. Строку не нужно добавлять отдельно, как в случае с методомdocument.createElement(), для создания нового TR элемента.

+ +

Спецификации

+ + + + + + + + + + + + + + + + + + + + + + + + +
СпецификацииСтатусКомментарии
{{SpecName("HTML WHATWG", "tables.html#dom-table-insertrow", "HTMLTableElement.insertRow()")}}{{Spec2("HTML WHATWG")}}
{{SpecName("DOM2 HTML", "html.html#ID-93995626", "HTMLTableElement.insertRow()")}}{{Spec2("DOM2 HTML")}}Specifies in more detail where the row is inserted.
{{SpecName("DOM1", "level-one-html.html#ID-39872903", "HTMLTableElement.insertRow()")}}{{Spec2("DOM1")}}Initial definition
+ +

Поддержка браузерами

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support4{{CompatVersionUnknown}}3[1]5.5104
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

[1] Начиная с Gecko 20.0 {{geckoRelease("20.0")}} аргумент index опционален и значением по умолчанию является -1 согласно спецификации HTML.

+ +

Смотри также

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