加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

twitter-bootstrap – 引导中的tabindex =“ – 1”是什么?

发布时间:2020-12-18 00:10:46 所属栏目:安全 来源:网络整理
导读:Bootstrap 3中的tabindex属性是什么? 它的文档并没有说明什么,尽管他们在所有模式中都使用它们。 我只是发现这个关于它的使用,这并没有真的说得太多 Accessible tooltips for keyboard and assistive technology users For users navigating with a keybo
Bootstrap 3中的tabindex属性是什么?

它的文档并没有说明什么,尽管他们在所有模式中都使用它们。

我只是发现这个关于它的使用,这并没有真的说得太多

Accessible tooltips for keyboard and assistive technology users

For users navigating with a keyboard,and in particular users of assistive technologies,you should only add tooltips to keyboard-focusable elements such as links,form controls,or any arbitrary element with a tabindex=”0″ attribute.

我发现了I can’t press esc to hide a modal if the tabindex attribute is not -1

> Modal closing after pressing esc key (with tabindex)
> Modal not closing after pressing esc key (without tabindex)

解决方法

The tabindex attribute explicitly defines the navigation order for focusable elements (typically links and form controls) within a page. It can also be used to define whether elements should be focusable or not.

[Both] tabindex="0" and tabindex="-1" have special meaning and provide distinct functionality in HTML. A value of 0 indicates that the element should be placed in the default navigation order. This allows elements that are not natively focusable (such as <div>,<span>,and <p>) to receive keyboard focus. Of course one should generally use links and form controls for all interactive elements,but this does allow other elements to be focusable and trigger interaction.

A tabindex="-1" value removes the element from the default navigation flow (i.e.,a user cannot tab to it),but it allows it to receive programmatic focus,meaning focus can be set to it from a link or with scripting.** This can be very useful for elements that should not be tabbed to,but that may need to have focus set to them.

A good example is a modal dialog window – when opened,focus should be set to the dialog so a screen reader will begin reading and the keyboard will begin navigating within the dialog. Because the dialog (probably just a <div> element) is not focusable by default,assigning it tabindex="-1" allows focus to be set to it with scripting when it is presented.

A value of -1 can also be useful in complex widgets and menus that utilize arrow keys or other shortcut keys to ensure that only one element within the widget is navigable with the tab key,but still allow focus to be set on other components within the widget.

资料来源:http://webaim.org/techniques/keyboard/tabindex

这就是为什么你需要在模式< div>上使用tabindex =“ – 1”,所以用户可以访问常用的鼠标和键盘快捷键。希望有帮助。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读