如何使用 WAI-ARIA 通知屏幕阅读器 div 现在可见 [英] How to notify screen readers using WAI-ARIA that a div is now visible

查看:33
本文介绍了如何使用 WAI-ARIA 通知屏幕阅读器 div 现在可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 WAI-ARIA 通知屏幕阅读器 div 现在可见?

如果我们得到了 html

呈现主要内容

<div id="bar" style="display: none;">隐藏内容</div>

然后我们

$('#foo').hide();$('#bar').show();

我们如何通知屏幕阅读器他们应该通知用户现在可见的 div(或者可能自动关注现在可见的 div)?

解决方案

通常不需要告诉屏幕阅读器内容现在可见.使用 aria-hidden 在实践中没有区别,所以我建议不要使用它.如果您希望屏幕阅读器显示隐藏 div 的文本内容,您可以使用 role=alertaria-live=polite (例如).您可以将其用于希望屏幕阅读器听到的更新内容,而无需移动到内容位置来发现它.例如,一条没有获得焦点的弹出消息,但包含在用户按下按钮等操作后相关的文本信息.

更新:我与一位开发 ARIA 1.0 的人讨论过,他建议使用 HTML5 hidden 而不是 aria-hidden 作为内容被隐藏的语义指示.将它与 CSS display:none 结合用于旧浏览器.支持 HTML5 hidden 的浏览器在用户代理样式表中使用 display:none 实现它.

How do you notify screen readers using WAI-ARIA that a div is now visible?

If we got the html

<div id="foo">Present main content</div>
<div id="bar" style="display: none;">Hidden content</div>

and then we

$('#foo').hide();
$('#bar').show();

how do we notify screen readers that they should notify the user about the now visible div (or possibly automatically focus on the now visible div)?

解决方案

You do not need generally to tell screen readers that content is now visible. Use of aria-hidden makes no difference in practice, so I would suggest not using it. If you want the text content of the hidden div to be announced by a screen reader you may use role=alert or aria-live=polite (for example). You would use this for updated content that you want a screen reader to hear without having to move to the content location to discover it. For example a pop up message that does not receive focus, but contains text information that is relevant to a user after an action such as pressing a button.

update: I discussed with one of the people who developed ARIA 1.0, he suggested using HTML5 hidden instead of aria-hidden as a semantic indication that content is hidden. use it in conjunction with CSS display:none for older browsers. Browsers that support HTML5 hidden implement it using display:none in the user agent style sheet.

这篇关于如何使用 WAI-ARIA 通知屏幕阅读器 div 现在可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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