html - <button> 需要角色 ="button"吗?

标签 html twitter-bootstrap accessibility wai-aria

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

<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>

无障碍软件是否已经知道 button 元素是用来充当按钮的?我有什么理由应该在我的代码中包含 role="button" 和/或 type="button" 吗?

最佳答案

许多 HTML5 元素都带有默认的隐式 ARIA 语义,并且显式设置这些默认值是“unnecessary and not recommended”。

查看 button element ,你可以看到它有 button role默认情况下。

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

关于html - <button> 需要角色 ="button"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26934719/

相关文章:

html - bootstrap 3 中带下拉菜单的导航丸

javascript - 如果正在使用屏幕阅读器,我想禁用音频事件

javascript - Style.length 和 Style.width 不起作用

html - 如何使用 css 让子 div 单独响应?

ruby-on-rails - Heroku ruby​​ on rails 资源部署问题

css - bootstrap 4 上的固定宽度侧边栏,其中主要区域在移动设备上消失

html - 使用 <a> 或 <a role ="button"> 进行可访问性的更好做法是什么?

css - 将 tabindex 添加到 css :after content

html - 如何在UIWebView IOS上显示html内容

jquery - 如何使 <ul> 充当 <ol> (使用数字而不是元素符号)?