HTMLTableCellElement: scope 屬性
HTMLTableCellElement 介面的 scope 屬性指示了 <th> 單元格的範圍。
可以使用 scope 屬性配置表頭單元格,使其應用於指定的行或列,或者應用於當前行組中尚未定義範圍的單元格(即,具有相同祖先 <thead>、<tbody> 或 <tfoot> 元素)。如果 scope 沒有指定值,則表頭不會以這種方式直接與單元格關聯。scope 的允許值為:
注意: 此屬性在瀏覽器中沒有視覺效果。它添加了語義資訊,以幫助螢幕閱讀器等輔助技術以更連貫的方式呈現表格。
值
以下值之一
col-
表頭單元格應用於同一列中的後續單元格(如果同時使用了
colspan,則應用於多列),直到該列的末尾,或者該列中的另一個<th>建立新的範圍。 colgroup-
表頭單元格應用於當前列組中尚未應用範圍的所有單元格。僅當單元格位於列組中時,才允許使用此值。
row-
表頭單元格應用於同一行中的後續單元格(如果同時使用了
rowspan,則應用於多行),直到該行的末尾,或者同一行中的另一個<th>建立新的範圍。 rowgroup-
表頭單元格應用於當前行組中尚未應用範圍的所有單元格。僅當單元格位於行組中時,才允許使用此值。
- 空字串(
"") -
表頭單元格沒有預定義的範圍;使用者代理將根據上下文線索確定範圍。
示例
此示例為 tbody 中第一行的所有單元格添加了一個標籤。
HTML
html
<table>
<caption>
Tallest Dams
</caption>
<tr>
<td></td>
<th scope="col">Dam</th>
<th scope="col">Country</th>
<th scope="col">Height</th>
</tr>
<tr>
<td>1.</td>
<th scope="row">Jinping-I Dam</th>
<td>China</td>
<td>305 m</td>
</tr>
<tr>
<td>2.</td>
<th scope="row">Nurek Dam</th>
<td>Tajikistan</td>
<td>300 m</td>
</tr>
<tr>
<td>3.</td>
<th scope="row">Lianghekou Dam</th>
<td>China</td>
<td>295 m</td>
</tr>
<tr>
<td>4.</td>
<th scope="row">Xiowan Dam</th>
<td>China</td>
<td>292 m</td>
</tr>
<tr>
<td>5.</td>
<th scope="row">Balhetan Dam</th>
<td>China</td>
<td>289 m</td>
</tr>
<tr>
<td>6.</td>
<th scope="row">Xiluodu Dam</th>
<td>China</td>
<td>285.5 m</td>
</tr>
<tr>
<td>7.</td>
<th scope="row">Grande-Dixence Dam</th>
<td>Switzerland</td>
<td>285 m</td>
</tr>
</table>
結果
規範
| 規範 |
|---|
| HTML # dom-th-scope |
瀏覽器相容性
載入中…