简体   繁体   English

屏幕阅读器和 JavaScript 焦点事件的可访问性?

[英]Accessibility with screen-readers and JavaScript focus events?

I have a form that has some JavaScript to advance to the next field when valid text is entered (sample below).我有一个表单,其中包含一些 JavaScript,可以在输入有效文本时前进到下一个字段(示例如下)。 My question is how is this handled by a screen-reader.我的问题是屏幕阅读器是如何处理的。 Will this confuse the reader or will it detect the change in focus and read the new field out to the user?这会让读者感到困惑还是会检测到焦点的变化并将新字段读出给用户?

HTML HTML

<form action="/some/action" method="post" role="form">
    <legend>A Form</legend>
    <label for="first_number">First Number</label>
    <input id="first_number" name="first_number" required type="text" value="">
    <label for="second_number">Second Number</label>
    <input id="second_number" name="second_number" required type="text" value="">
    <button type="submit">Submit</button>
</form>

JavaScript JavaScript

(function (document, window) {
    function getFocusCallback(current_focus, go) {
        var check = document.getElementById(current_focus);
        var el = document.getElementById(go);
        var pat = new RegExp('^\\d{3}$');
        return function callback() {
            if (pat.test(check.value)) {
                el.focus();
            }
        };
    }

    document.getElementById('first_number').addEventListener('input', getFocusCallback('first_number', 'second_number'));
})(document, window);

So after the user has entered three digits in the first field, the focus method is called on the second.因此,在用户在第一个字段中输入三个数字后,将在第二个字段中调用 focus 方法。

I think that the issue here is unexpected behavior .我认为这里的问题是意外行为 For non-sighted users, any non-standard behavior could be a possible source of confusion, since it would work differently than every other website.对于没有视力的用户,任何非标准行为都可能造成混淆,因为它的工作方式与其他网站不同。

Also, is this a feature that you'd have on every field, or just some of them?此外,这是您在每个领域都会拥有的功能,还是只是其中一些领域? If you have multiple fields with different behavior, that would be especially confusing.如果您有多个具有不同行为的字段,那将特别令人困惑。

There was a pretty good thread about this a couple of years ago with input from several people way more knowledgeable than myself.几年前有一个关于这个的很好的线索,有几个比我更了解的人的意见。 https://lists.w3.org/Archives/Public/w3c-wai-ig/2015AprJun/0162.html https://lists.w3.org/Archives/Public/w3c-wai-ig/2015AprJun/0162.html

You'll need to click the " Next message " link at the bottom of each page to read all messages in the thread.您需要单击每个页面底部的“下一条消息”链接才能阅读线程中的所有消息。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM