元素:ariaReadOnly 属性

Baseline 2023
新推出

自 ⁨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">Enter the tags for the article</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"

规范

规范
无障碍富互联网应用程序 (WAI-ARIA)
# dom-ariamixin-ariareadonly

浏览器兼容性

另见