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

查看:38
本文介绍了我需要角色=“按钮"吗?在<按钮>上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到在所有使用 button 元素的 Bootstrap 示例中,它们包括 role="button"(和 type="button">),例如:

辅助功能软件难道不知道 button 元素是用来充当按钮的吗?我有什么理由应该在我的代码中包含 role="button" 和/或 type="button"?

解决方案

许多 HTML5 元素带有默认的隐式 ARIA 语义,并且显式设置这些默认值是不必要且不推荐".

查看按钮元素,可以看到它有button 角色 默认.

因此,设置 role="button" 是不推荐"的,但允许.它可能帮助那些支持 WAI-ARIA 但不支持 HTML5 的老用户代理.

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>

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?

解决方案

Many HTML5 elements come with default implicit ARIA semantics, and explicitly setting these default values is "unnecessary and not recommended".

Looking at the button element, you can see that it has the button role by default.

So, setting role="button" is "not recommended", but allowed. It might help older user agents that support WAI-ARIA but not HTML5.

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

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