元素: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

瀏覽器相容性

另見