简体   繁体   English

有没有一种方法可以专注于屏幕阅读器的文本元素(div,h标签,跨度)

[英]Is there a way to focus on a text element (div,h tags, span) for screen readers

I have a popup on my page and it opens on certain condition, like adding more than n number of items in the basket. 我的页面上有一个弹出窗口,它会在一定条件下打开,例如在购物篮中添加n个以上的项目。 When the popup opens, the close button of the popup is 'focused'. 当弹出窗口打开时,弹出窗口的关闭按钮被“聚焦”。 So a user using a screenreader would have no idea which close button they are hearing about. 因此,使用屏幕阅读器的用户不知道他们正在听哪个关闭按钮。

Is there a way to focus on the text first so that the user is aware of the popup and what it says, allowing them to have the same experience as a normal user? 有没有一种方法可以首先关注文本,以便用户知道弹出窗口及其内容,从而使他们具有与普通用户相同的体验?

I tried changing the order of the HTML elements(ex: text element first and button after) but that didn't work. 我尝试更改HTML元素的顺序(例如,先是文本元素,然后是按钮),但这没有用。

<div class="popup__container" style="opacity: 1; transform: matrix(1, 0, 0, 1, 0, 0);">
  <a href="#" class="popup__logo">
    <svg class="icon">
      <use xlink:href="#icon-logo"></use>
    </svg>
  </a>
  <button class="popup__close">
    <span>Close</span>
    <svg class="icon">
      <use xlink:href="#icon-close"></use>
    </svg>
  </button>
  <div class="popup__content">
    <div id="{9B6A4-272-46F7-9E21-4CE80C73A}" class="no-startendmargin theme-white" data-label-close="Close">
      <p>Starting from 15 products, you get a exclusive discount, find out more <a href="#groupProduct">Group product</a>.</p>
    </div>
  </div>
</div>

Basically, what you should do is implement a modal dialog. 基本上,您应该做的是实现模式对话框。

If you want a simpler solution for modern browsers, consider using the HTML5 native <dialog> element, MDN link is here . 如果您想为现代浏览器提供一个更简单的解决方案,请考虑使用HTML5本机<dialog>元素, 此处为MDN链接 Thus you'll get the Close button, focusability and even Windows-like experience and cursor restriction (seems to be a JAWS-specific feature), all of that free of charge. 因此,您将获得“关闭”按钮,可聚焦性以及什至类似于Windows的体验和光标限制(似乎是JAWS特有的功能),所有这些都是免费的。

If for some reason the native solution is not suitable for you, consider using plugins like Modaal or manually adding corresponding ARIA roles like dialog , for instance. 如果由于某种原因本机解决方案不适合您,请考虑使用Modaal之类的插件,或者手动添加诸如dialog类的相应ARIA角色。

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

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