HTMLTableCellElement: abbr 属性
HTMLTableCellElement 接口的 abbr 属性表示单元格的缩写。如果该单元格不代表标题单元格 <th>,则该属性将被忽略。
它反映了 <th> 元素的 abbr 属性。
注意:此属性在浏览器中没有视觉效果。它会添加信息以帮助辅助技术(如屏幕阅读器)使用此缩写。
值
字符串。
示例
此示例使用与每行第一个单元格的行标题关联的缩写来添加前缀。
HTML
html
<table>
<thead>
<tr>
<th abbr="Maker">Manufacturer</th>
<th abbr="Model">Car model</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tesla</td>
<td>3</td>
</tr>
<tr>
<td>BYD</td>
<td>Dolphin</td>
</tr>
<tr>
<td>VW</td>
<td>ID.3</td>
</tr>
</tbody>
</table>
JavaScript
js
const rows = document.querySelectorAll("thead tr");
const cells = rows[0].cells;
for (const cell of cells) {
cell.textContent = `${cell.textContent} (${cell.abbr})`;
}
结果
规范
| 规范 |
|---|
| HTML # dom-th-abbr |
浏览器兼容性
加载中…