【发布时间】:2023-06-18 22:49:01
【问题描述】:
我有一个文本input,它要求用户输入具有特定约束的密码。这些约束的帮助文本在单独的 DOM 元素中指定。
我希望屏幕阅读器在用户关注输入字段时阅读此帮助文本。我找到了两种方法:
-
在输入文本上使用
aria-describedby="help-text-id"。<label for="password"> Password </label> <input type="text" aria-describedby="help-text" id="password" /> <span id="help-text"> The password should at least be 8 characters</span> 在输入文本上使用
aria-labelledby="label-id help-text-id"读取对应的标签以及帮助文本作为标签
<label id="password-label"> Password </label>
<input type="text" aria-labelledbyby="password label help-text" />
<span id="help-text"> The password should at least be 8 characters</span>
我喜欢第一个,因为从语义上讲,此帮助文本是描述输入的内容,而不是标记输入的内容。 我只是不确定这是否是处理此问题的正确方法。还有其他的帮助文本发布模式吗?
另外,aria-describedby 似乎不适用于 ChromeVox 扩展程序,也不适用于 Windows 10 屏幕阅读器。
参考:https://developer.paciellogroup.com/blog/2018/09/describing-aria-describedby/
【问题讨论】:
标签: html accessibility