此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

HTMLTableCellElement:abbr 属性

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

HTMLTableCellElement 接口的 abbr 属性指示与单元格相关联的缩写。如果单元格不是表头单元格 <th>,则忽略该属性。

它反映 <th> 元素的 abbr 属性。

备注:此属性在浏览器中不具有视觉效果。它添加信息以帮助辅助技术(像屏幕阅读器)能够使用这个缩写。

一个字符串。

示例

此示例将每个第一单元格的行表头相关联的缩写添加为前缀。

HTML

html
<table> <thead> <tr> <th abbr="Maker">制造商</th> <th abbr="Model">汽车型号</th> </tr> </thead> <tbody> <tr> <td>特斯拉</td> <td>3</td> </tr> <tr> <td>比亚迪</td> <td>海豚</td> </tr> <tr> <td>大众</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})`; } 

结果

规范

Specification
HTML
# dom-th-abbr

浏览器兼容性