[英]How to properly show an error message inside a fieldset
I want to have a fieldset
-tag to show an error message. 我想要一个
fieldset
-tag来显示错误消息。
When doing something like: 当做类似的事情时:
<fieldset>
<legend>Some Legend</legend>
<div role="alert" aria-live="assertive" aria-relevant="all">
My Error Message
</div>
...
<!-- formfields -->
</fieldset>
The screen reader isn't reading the error message, but when wrapping the error message inside the <label>
-tag it is reading it but it feels wrong. 屏幕阅读器没有读取错误消息,但是将错误消息包装在
<label>
-tag中时,它正在读取错误消息,但是感觉不对。
What would be the proper way to show an error message inside a fieldset
-tag in terms of accessibility? 就可访问性而言,在
fieldset
-tag中显示错误消息的正确方法是什么?
aria-live
regions work pretty well if you follow a few simple rules. 如果您遵循一些简单的规则,那么
aria-live
区域的效果会很好。
aria-live
must exist at page load time. aria-live
的元素必须在页面加载时存在。 that is, you can't dynamically add that attribute after the page is loaded. aria-relevant
value (that is, if you don't specify aria-relevant
), then changes are only announced if you change the text in the region or if you add child DOM nodes. aria-relevant
值(即,如果您未指定aria-relevant
),则仅当您更改区域中的文本或添加子DOM节点时,才会宣布更改。 In your case, you have "all" so child DOM nodes that are removed will also be announced. A few side notes: 一些注意事项:
aria-live="polite"
is sufficient for the majority of cases. aria-live="polite"
就足够了。 aria-live="assertive"
is rarely needed except for extremely urgent messages. aria-live="assertive"
。 role="alert"
gives you an implicit aria-live="assertive"
. role="alert"
给您一个隐式的aria-live="assertive"
。 you don't have to specify aria-live
. aria-live
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.