何时对输入元素使用 required 属性与 aria-required 属性? [英] When to use the required attribute vs the aria-required attribute for input elements?

查看:86
本文介绍了何时对输入元素使用 required 属性与 aria-required 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使表单易于访问.我应该让我的输入同时具有 requiredaria-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>

文章可访问的 HTML5 表单 - 必需的输入声称它最好同时实施.

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.

您可以在 Steve Faulkner(ARIA 规范的编辑之一)于 2015 年撰写的这篇文章中详细了解您可以转储的 ARIA 属性:http://html5doctor.com/on-html-belts-and-aria-braces/

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/

这篇关于何时对输入元素使用 required 属性与 aria-required 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆