简体   繁体   English

更改 html 的焦点

[英]Changing focus for html Accessibility

I have a page that has a form with a submit button.我有一个带有提交按钮的表单的页面。 Once I click the submit button I would like for the focus to go to the "success" or "failure" message.单击提交按钮后,我希望将焦点集中到 go 到“成功”或“失败”消息。 Right now the screen reader doesn't leave the button once it is pressed.现在屏幕阅读器一旦按下按钮就不会离开。 It stays on the "Press Continue button" and I have the then navigate off with my arrows.它停留在“按继续按钮”上,然后我用我的箭头导航。 I would like for it to focus on the我希望它专注于

tag that takes the place of the button on the screen and read the message after pressing Continue.标签取代屏幕上的按钮并在按继续后阅读消息。

<form>
<h1> Start Password Reset> </h1>
<input placeholder="Email">
<input type="submit" name="Continue" value="Continue">
<p id="success"> Success Message Here </p>
<p id="failure"> Failure Message Here </p>
</form>

Focus normally applies to actionable elements.焦点通常适用于可操作的元素。 A status message like this is not actionable.像这样的状态消息是不可操作的。 Focusing it (which requires marking it with a focus indicator, for accessibility) could confuse users into believing that they can activate it.聚焦它(这需要用焦点指示器标记它,以便访问)可能会让用户误以为他们可以激活它。

I get the impression that you want to direct attention to the message, and nothing more than that.我得到的印象是您想将注意力集中在该消息上,仅此而已。 If so, you could style it so it attracts attention, and you could also locate it in a live region so that assistive technologies will notify users about the message.如果是这样,您可以设置样式以吸引注意力,还可以将其定位在实时区域中,以便辅助技术将消息通知用户。

For that purpose you could make the live region initially empty, and then fill it with one or the other message after the user activates the button.为此,您可以使活动区域最初为空,然后在用户激活按钮后用一条或另一条消息填充它。

Applying the attribute role="status" to a “p” element makes it such a live region.将属性 role="status" 应用于“p”元素使其成为这样一个活动区域。

Giving that “p” element an id="xyz" attribute and the button an aria-controls="xyz" attribute will also explicitly associate the eventual message with the button.给“p”元素一个 id="xyz" 属性和一个 aria-controls="xyz" 属性的按钮也会显式地将最终消息与按钮相关联。

If the button disappears after being activated, you will need to choose the most useful and intuitive element to move the focus to, which would normally be an element that the user can do something with.如果按钮在被激活后消失,您将需要选择最有用和最直观的元素来移动焦点,这通常是用户可以使用的元素。

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

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