HTMLTableRowElement: sectionRowIndex 屬性
HTMLTableRowElement 介面的只讀屬性 sectionRowIndex 表示行在當前 section(<thead>、<tbody> 或 <tfoot>)中的位置。
值
行的索引,如果行不屬於該 section,則為 -1。
示例
此示例使用 JavaScript 來標記 tbody 中所有行的編號。
HTML
html
<table>
<thead>
<tr>
<th>Item</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bananas</td>
<td>$2</td>
</tr>
<tr>
<td>Oranges</td>
<td>$8</td>
</tr>
<tr>
<td>Top Sirloin</td>
<td>$20</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Total</td>
<td>$30</td>
</tr>
</tfoot>
</table>
JavaScript
js
const rows = document.querySelectorAll("tbody tr");
rows.forEach((row) => {
const z = document.createElement("td");
z.textContent = `(row #${row.sectionRowIndex})`;
row.appendChild(z);
});
結果
規範
| 規範 |
|---|
| HTML # dom-tr-sectionrowindex |
瀏覽器相容性
載入中…