简体   繁体   English

在“ <input> 无法访问。 是否有一种简单的方法使其可访问(JS),还是我必须放弃它?

[英]Using “required” on an <input> isn't accessible. Is there an easy way to make it accessible (JS) or do I have to abandon it?

My form has several input fields (email, first name, last name, etc.) that all use the "required" property. 我的表单有几个输入字段(电子邮件,名字,姓氏等),全部使用“ required”属性。

<input required></input>

This causes a nice universal error message to display in each browser, and lets the browser validate the inputs for me. 这会在每个浏览器中显示一个不错的通用错误消息,并让浏览器为我验证输入。

However, according to Accessible360, screen readers can't read those error messages. 但是,根据Accessible360,屏幕阅读器无法读取这些错误消息。

Is there a way to fix this that doesn't involve adding a bunch of extra tags, attributes, aria attributes, text, and Javascript? 有没有一种方法可以解决此问题,而无需添加大量额外的标签,属性,aria属性,文本和Javascript? Maybe just a little Javascript that will convert those in-browser errors into alerts? 也许只是一个Javascript会将浏览器内的错误转换为警报? I'm trying to keep my code clean. 我正在尝试保持代码清洁。

Thanks, I appreciate your help. 谢谢,谢谢您的帮助。

The problem is not the presence of the required attribute which should be encouraged. 问题不在于应鼓励的required属性的存在。 Back in 2012, Using the required attribute to indicate a required input field has been added a note about screenreader support. 早在2012年,就添加了关于屏幕阅读器支持的注释,即使用required属性指示必填字段 That was 7 years ago, and now the support is good with recent screenreaders. 那是7年前的事,现在,最近的屏幕阅读器提供了很好的支持。

Now the problem is that you must have a visual indication about required fields: H90: Indicating required form controls using label or legend and that you must indicate fields with errors G83: Providing text descriptions to identify required fields that were not completed 现在的问题是,您必须具有关于必填字段的直观指示: H90:使用标签或图例指示必填表单控件 ,并且必须指示带有错误的字段G83:提供文本描述以标识未完成的必填字段

The Paciello group has a good up-to-date page about that subject : Required attribute requirements which provide more informations about screenreader / browser support (" with the exception of using TalkBack with Firefox and Chrome on Android. ") and using aria-invalid or aria-describedby if a field has errors. Paciello组在该主题上有一个很好的最新页面: 必需的属性要求 ,它提供有关屏幕阅读器/浏览器支持的更多信息(“ ,但在Android上使用Firefox和Chrome使用TalkBack除外。 ”)以及使用aria-invalid或用aria-describedby如果字段有错误。

I imagine you can use jQuery to dynamically add the tags you need to all inputs with required. 我想您可以使用jQuery将所需的标签动态添加到具有所需的所有输入中。 For the required before HTML5 I think it's aria-required... 对于HTML5之前的必需文件,我认为它是aria必需的...

$(':input[required]').prop('aria-required',true);

According to Mozilla with aria-required screen readers should announce the field as required. Mozilla认为 ,必须使用咏叹调的屏幕阅读器应按要求宣布该字段。

For an alert you can have a script checking if all required inputs have a value onSubmit. 对于警报,您可以使用脚本检查是否所有必需的输入都具有onSubmit值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 不在全局范围内的易于访问的变量 - Easy accessible variable that isn't in the Global scope 如何生成 URL 并使用 PWA 离线访问它? - How do I generate a URL and make it accessible using PWA offline? 有没有办法做一个可访问的模式? - Is there a way to do an accessible modal? Vue.js - 无法访问数据属性 - Vue.js - Data Property isn't accessible 当构造函数作为对象被调用时,如何使构造函数具有可访问的成员 - How do I make a constructor have accessible members when its called as an object 如何使我的 react 应用程序的一部分仅对订阅者开放? - How do I make a section of my react app only accessible to those who have subscribed? 如何在保持切换功能的同时使输入值可访问? - How do I make the input values accessible while keeping the toggle functionality? &#39;SQLite 错误:没有这样的表&#39;,在连接的数据库上使用 TypeORM,其他表可访问。 有没有特定的方法来访问带有外键的表? - 'SQLite Error: No Such Table' with TypeORM on a connected DB with other tables accessible. Is there a specific way to reach tables with foreign keys? js插件如何使IIFE中的功能可访问? - How do js plug-ins make functions in IIFE accessible? 我在哪里可以放置javascript函数以使其可访问? - Where do I put javascript functions in grails to have it accessible?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM