什么是HTML tabindex属性? [英] What is the HTML tabindex attribute?

查看:114
本文介绍了什么是HTML tabindex属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML中使用的 tabindex 属性是什么?

What is the tabindex attribute used for in HTML?

推荐答案

tabindex 全局属性 负责两件事:

tabindex is a global attribute responsible for two things:


  1. 它设置可聚焦元素的顺序和
  2. 使元素可聚焦

  1. it sets the order of "focusable" elements and
  2. it makes elements "focusable'.

在我看来,第二件事情比第一件更重要。默认情况下可聚焦的元素很少(例如< a>和表单控件)。开发人员经常在不可聚焦的元素(< div> ;,< span>和等等),以及使界面不仅能够响应鼠标事件而且还能响应键盘事件(例如'onkeypress')的方式我正在使这些元素变得可以聚焦。在最后一种情况下,如果您不想设置订单,但只需让您的元素可以在所有这些元素上使用 tabindex =0

To my mind the second thing is even more important then the first one. There are very few elements that are focusable by default (e.g. <a> and form controls). Developers very often add some JavaScript event handlers (like 'onclick') on not focusable elements (<div>, <span> and so on). And the way to make your interface to be responsive not only to mouse events but to keyboard events (e.g. 'onkeypress') as well is making such elements focusable. And in the last case if you don't want to set the order but just make your element focusable use tabindex="0" on all such elements:

<div tabindex="0"></div>

另外,如果您不希望它通过tab键进行调整,请使用的tabindex = - 1。例如,下面的链接将不会集中使用tab键来遍历。

Also if you don't want it to be focusable via the tab key then use tabindex="-1". For example the below link will not be focused while using tab keys to traverse.

<a href="#" tabindex="-1">Tab key cannot reach here!</a>

这篇关于什么是HTML tabindex属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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