A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/zh-CN/docs/Web/API/HTMLTableRowElement/sectionRowIndex below:

HTMLTableRowElement:sectionRowIndex 属性 - Web API

HTMLTableRowElement:sectionRowIndex 属性

Baseline Widely available

HTMLTableRowElement 接口的 sectionRowIndex 只读属性表示当前部分(<thead>、<tbody> 和 <tfoot>)的行位置。

值

返回该行的索引,如果该行不属于表的一部分,则返回 -1。

示例

本示例使用 JavaScript 标记表 tbody 中的所有行号。

HTML
<table>
  <thead>
    <tr>
      <th>商品</th>
      <th>ä»·æ ¼</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>香蕉</td>
      <td>$2</td>
    </tr>
    <tr>
      <td>橘子</td>
      <td>$8</td>
    </tr>
    <tr>
      <td>西冷牛排</td>
      <td>$20</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td>总计</td>
      <td>$30</td>
    </tr>
  </tfoot>
</table>
JavaScript
const rows = document.querySelectorAll("tbody tr");

rows.forEach((row) => {
  const z = document.createElement("td");
  z.textContent = `(行 #${row.sectionRowIndex})`;
  row.appendChild(z);
});
结果 规范 浏览器兼容性 参见

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4