问题描述
我正在尝试使表单可访问。我是否应该输入必需
和 aria-required
属性,或只有一个?
I'm trying to make a form accessible. Should I make my inputs have both required
and aria-required
attributes, or just one?
<label for="textbox1">Input</label>
<input id="textbox1" type="text" name="Text Box" required>
或者这样?
<label for="textbox1">Input</label>
<input id="textbox1" type="text" name="Text Box" aria-required="true">
或者这样?
<label for="textbox1">Input</label>
<input id="textbox1" type="text" name="Text Box" aria-required="true" required>
文章声称最好同时实现它们。
The article Accessible HTML5 Forms – Required Inputs claims it is best to implement both.
推荐答案
当John Foliot在2012年写这篇文章时,这是非常真实的。你需要两者。
When John Foliot wrote that article in 2012 it was very much true. You needed both.
今天不再是这种情况了。我可以举个例子,把它放在CodePen中,并在JAWS和NVDA中查看(对不起,没有VoiceOver)今天):
Today that is no longer the case. I can take your example, put it in a CodePen, and check it in JAWS and NVDA (sorry, no VoiceOver today):
<label for="textbox1">Input</label>
<input id="textbox1" type="text" name="Text Box" required>
您将很高兴知道NVDA和JAWS都会根据需要宣布该字段。
You will be happy to know that both NVDA and JAWS announce the field as required.
简而言之,不需要 aria-required
。只需使用 required
。
In short, you do not need aria-required
any longer. Just use required
.
您可以阅读更多关于您可以在本文中转储的ARIA属性的信息。 2015年Faulkner(ARIA规范的编辑之一):
You can read a bit more about the ARIA attributes you can dump in this article by Steve Faulkner (one of the editors of the ARIA spec) from 2015: http://html5doctor.com/on-html-belts-and-aria-braces/
这篇关于何时使用必需属性与输入元素的aria-required属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!