ElementInternals: ariaInvalid 屬性
ElementInternals 介面的 ariaInvalid 屬性反映了 aria-invalid 屬性的值。該屬性與 application、checkbox、combobox、gridcell、listbox、radiogroup、slider、spinbutton、textbox 和 tree 角色相關,它向輔助功能 API 指出輸入的值是否不符合應用程式預期的格式。
注意: 在 ElementInternals 上設定 ARIA 屬性允許為自定義元素定義預設語義。這些語義可能會被作者定義的屬性覆蓋,但可以確保在作者刪除這些屬性或根本未新增這些屬性時,預設語義仍然保留。有關更多資訊,請參閱 Accessibility Object Model explainer。
值
一個字串,其值可能為以下之一:
"true"-
元素無效。
"false"(預設)-
元素處於非無效狀態。
"grammar"-
元素因檢測到語法錯誤而處於無效狀態。
"spelling"-
元素因檢測到拼寫錯誤而處於無效狀態。
示例
在此示例中,我們定義並建立了一個 <custom-text> 元素,然後從文件中的第一個 <custom-text> 元素檢索 ariaInvalid 的值。
js
class CustomControl extends HTMLElement {
constructor() {
super();
this._internals = this.attachInternals();
this._internals.ariaInvalid = "false";
}
// …
}
window.customElements.define("custom-text", CustomControl);
const element = document.querySelector("custom-text");
console.log(element._internals.ariaInvalid);
規範
| 規範 |
|---|
| 無障礙富網際網路應用程式 (WAI-ARIA) # dom-ariamixin-ariainvalid |
瀏覽器相容性
載入中…