我是否需要角色=“按钮”?在< button>上? [英] Do I need role="button" on a <button>?

查看:74
本文介绍了我是否需要角色=“按钮”?在< 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.

这篇关于我是否需要角色=“按钮”?在&lt; button&gt;上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆