我是否需要角色=“按钮”?在< button>上?
在Bootstrap的所有示例中,我都使用 button
元素,其中包括 role = button
(和 type = button
),例如:
I've noticed in all of Bootstrap's examples using button
elements, they include role="button"
(and type="button"
), such as:
<div class="dropdown">
<button id="dLabel" type="button" role="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
Dropdown trigger <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
...
</ul>
</div>
可访问性软件是否已经知道按钮
元素旨在充当按钮吗?有什么理由在我的代码中包含 role = button
和/或 type = button
吗?
Won't accessibility software already know that a button
element is meant to act as a button? Is there any reason I should include role="button"
and/or type="button"
in my code?
许多HTML5元素都带有默认隐式ARIA语义,并且将这些默认值明确设置为 不必要且不推荐 。
Many HTML5 elements come with default implicit ARIA semantics, and explicitly setting these default values is "unnecessary and not recommended".
查看 button
元素,您会看到它具有 button
角色默认情况下。
Looking at the button
element, you can see that it has the button
role by default.
因此,不建议设置 role = button
,但可以。 可能可以帮助支持WAI-ARIA但不支持HTML5的旧用户代理。
So, setting role="button"
is "not recommended", but allowed. It might help older user agents that support WAI-ARIA but not HTML5.