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

View in English Always switch to English

Element:ariaReadOnly 属性

基线
广泛可用

自 2023年10月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

Element 接口的 ariaReadOnly 属性反映 aria-readonly 属性的值,指示元素不可编辑,但仍可操作。

备注:应尽可能使用 type="text" 的 HTML <input> 元素或 <textarea>,因为它们内置语义,无需 ARIA 属性。

具有以下值之一的字符串:

  • "true"
    • :用户不能更改该元素的值。
  • "false"
    • :用户可以设置该元素的值。

示例

此示例中,ID 为 txtBoxInput 的元素上的 aria-readonly 属性设为 "true",表示该输入当前为只读。使用 ariaReadOnly 将其更新为 "false"

html
<div id="txtboxMultilineLabel">输入文章的标签</div>
<div
  role="textbox"
  id="txtBoxInput"
  contenteditable="true"
  aria-multiline="true"
  aria-labelledby="txtboxMultilineLabel"
  aria-readonly="true"></div>
js
let el = document.getElementById("txtBoxInput");
console.log(el.ariaReadOnly); // "true"
el.ariaReadOnly = "false";
console.log(el.ariaReadOnly); // "false"

规范

规范
Accessible Rich Internet Applications (WAI-ARIA)
# dom-ariamixin-ariareadonly

浏览器兼容性

参见