大网数据广告活动
Web 标准与前端开发

Element: ariaInvalid property

· 52CE 我爱测

The **`ariaInvalid`** property of the Element interface reflects the value of the `aria-invalid` attribute. Relevant for the `application`, `checkbox`, `combobox`, `gridcell`, `listbox`, `radiogroup`, `slider`, `spinbutton`, `textbox`, and `tree` roles, it indicates to the access

DOM

The ariaInvalid property of the Element interface reflects the value of the aria-invalid attribute. Relevant for the application, checkbox, combobox, gridcell, listbox, radiogroup, slider, spinbutton, textbox, and tree roles, it indicates to the accessibility API whether the entered value does not conform to the format expected by the application.

If the attribute is not present, or is set to the empty string, assistive technology will treat the value as if it were set to false. If the attribute is present but set to a value other than false, grammar, spelling or the empty string (""), assistive technology treats the value as true. The property reflects the attribute value as set, not as handled by assistive technology.

Value

A string with one of the following values:

  • "true"
    • : The element is invalid.
  • "false" (default)
    • : The element is not in an invalid state.
  • "grammar"
    • : The element is in an invalid state because grammatical error was detected.
  • "spelling"
    • : The element is in an invalid state because spelling error was detected.

Examples

In this example the aria-invalid attribute on the element with an ID of quote is omitted, returning null and treated as false. Using ariaInvalid we update the value to grammar (because there are two errors).

<div id="quote" role="textbox" contenteditable>you are your best thing..</div>
<hr />
<pre id="log"></pre>
const logElement = document.querySelector("#log");
function log(text) {
  logElement.innerText = `${logElement.innerText}${text}\n`;
  logElement.scrollTop = logElement.scrollHeight;
}
const el = document.getElementById("quote");
log(`Initial value: ${el.ariaInvalid}`);
el.ariaInvalid = "grammar";
log(`Updated value: ${el.ariaInvalid}`);

Examples

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。