简体   繁体   English

JAWS为什么仍读取隐藏的表单元素?

[英]Why are hidden form elements still read by JAWS?

The Situation 情况

I have an area of the screen that can be shown and hidden via JavaScript (something like "show/hide advanced search options"). 我有一个可以通过JavaScript显示和隐藏的屏幕区域(类似“显示/隐藏高级搜索选项”)。 Inside this area there are form elements (select, checkbox, etc). 在该区域内有表单元素(选择,复选框等)。 For users using assistive technology like a screen-reader (in this case JAWS), we need to link these form elements with a label or use the "title" attribute to describe the purpose of each element. 对于使用屏幕阅读器(在本例中为JAWS)等辅助技术的用户,我们需要将这些表单元素与标签链接,或使用“ title”属性来描述每个元素的用途。 I'm using the title attribute because there isn't enough space for a label, and the tooltip you get is nice for non-screen-reader users. 我之所以使用title属性,是因为标签没有足够的空间,并且您获得的工具提示对非屏幕阅读器用户来说非常好。

The code looks something like this: 代码看起来像这样:

<div id="placeholder" style="display:none;">
  <select title="Month">
    <option>January</option>
    <option>February</option>
    ...
  </select>
</div>

The Problem 问题

Normally, JAWS will not read hidden elements... because well, they're hidden and it knows that. 通常,JAWS不会读取隐藏的元素……因为它们是隐藏的,并且它知道这一点。 However, it seems as though if the element has a title set, JAWS reads it no matter what. 但是,似乎该元素已设置标题,无论如何JAWS都会读取它。 If I remove the title, JAWS reads nothing, but obviously this is in-accessible markup. 如果删除标题,JAWS不会读取任何内容,但是显然这是无法访问的标记。

Possible Solutions 可能的解决方案

My first thought was to use a hidden label instead of the title, like this: 我首先想到的是使用隐藏标签代替标题,如下所示:

<div id="placeholder" style="display:none;">
  <label for="month" style="display:none">Month</label>
  <select id="month">...</select>
</div>

This results in the exact same behavior, and now we lose the tool-tips for non-screen-reader users. 这会导致完全相同的行为,现在我们为非屏幕阅读器用户丢失了工具提示。 Also we end up generating twice as much Html. 同样,我们最终生成的HTML数量也增加了两倍。

The second option is to still use a label, put position it off the screen. 第二个选项是仍然使用标签,将其放置在屏幕之外。 That way it will be read by the screen-reader, but won't be seen by the visual user: 这样,屏幕阅读器就会读取它,但视觉用户不会看到它:

<div id="placeholder" style="display:none;">
  <label for="month" style="position:absolute;left:-5000px:width:1px;">Month</label>
  <select id="month">...</select>
</div>

This actually works, but again we lose the tool-tip and still generate additional Html. 这实际上是有效的,但是我们再次失去了工具提示,仍然生成了其他HTML。

My third possible solution is to recursively travel through the DOM in JavaScript, removing the title when the area is hidden and adding it back when the area is shown. 我的第三个可能的解决方案是递归地遍历JavaScript中的DOM,在隐藏区域时删除标题,并在显示区域时将其重新添加。 This also works... but is pretty ugly for obvious reasons and doesn't really scale well to a more general case. 这也可以工作...但是由于显而易见的原因,这很难看,并且不能很好地扩展到更一般的情况。

Any other ideas anyone? 还有其他想法吗? Why is JAWS behaving this way? 为什么JAWS表现为这种方式?

为项目提供aria-hidden =“ true”属性,并且该属性应从屏幕阅读器中隐藏。

This definitely looks like a bug in JAWS as the spec definitively states that display:none should cause an element and its children not to be displayed in any media. 这肯定看起来像JAWS中的错误,因为规范明确指出display:none不会导致元素及其子元素不显示在任何媒体中。

However, playing with the speak: aural property might be useful? 但是,玩弄讲话:听觉属性可能有用吗? I don't know as I don't have JAWS available. 我不知道,因为我没有可用的JAWS。

http://www.w3.org/TR/CSS2/aural.html#speaking-props http://www.w3.org/TR/CSS2/aural.html#speaking-props

Did you try this? 你有尝试过吗?

<div id="placeholder" style="display:none;">
  <select title="Month" style="speak:none;">
    <option>January</option>
    <option>February</option>
    ...
  </select>
</div>

This has worked for me in the past when I wanted to make JAWS read one thing, and skip over something else that would normally be read. 过去,当我想让JAWS读取一件事而跳过通常可以读取的其他内容时,这对我来说是有用的。

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

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