tabindex属性
描述 (Description)
The tabindex
is used to define a sequence that users follow when they use the Tab key to navigate through a page. By default, the natural tabbing order will match the source order in the markup. In certain circumstances it may be necessary to override the default tabbing order, but it’s strongly recommended that you craft a page in a logical flow and let the browser work through it in the default order—an approach that negates the need for the tabindex
attribute.
tabindex
用于定义用户使用Tab键浏览页面时遵循的顺序。 默认情况下,自然制表顺序将与标记中的源顺序匹配。 在某些情况下,可能有必要覆盖默认的制表顺序,但是强烈建议您以逻辑流程制作页面,并让浏览器以默认顺序浏览该页面-这种方法不需要使用tabindex
属性。
A tabindex
can start at 0 and increment in any value. As such, the sequence 1, 2, 3, 4, 5 would be fine, as would 10, 20, 30, 40, 50. If you need to introduce a tabindex
, it’s advisable to use a sequence that contains intervals (like the second example provided), as this will give you the opportunity to inject other controls later if need be (for example, 10, 15, 20) without having to reindex all the tabindex
values on the page. Should a given tabindex
value be applied to more than one element (e.g. all links in one section given a tabindex
of “1”, and sidebar links given a tabindex
of “2”), the tabbing order of those affected elements will be as per the source markup order. Many people will choose to use this approach rather than a sequence with a defined interval, such as 5, 10, 15, because it allows for additional links or form controls to be added without the headache of re-numbering. If a tabindex
of “-1” is used, the element it’s applied to will no longer be keyboard focusable.
tabindex
可以从0开始,可以任意增加。 因此,顺序1、2、3、4、5和10、20、30、40、50都可以。如果需要引入tabindex
,建议使用包含间隔的序列(例如提供第二个示例),因为这将使您有机会在以后需要时(例如10、15、20)注入其他控件,而不必重新索引页面上的所有tabindex
值。 如果将给定的tabindex
值应用于一个以上的元素(例如,一节中的所有链接的tabindex
为“ 1”,侧栏链接的tabindex
为“ 2”),则受影响元素的制表顺序将按照源标记顺序。 许多人会选择使用此方法,而不是使用具有定义间隔的序列,例如5、10、15,因为它允许添加其他链接或表单控件,而无需重新编号。 如果使用tabindex
为“ -1”,则应用于该元素的元素将不再是键盘可聚焦的。
If a tabindex
is set anywhere on a page—even if it’s the hundredth link or the fiftieth form control—the tab order will start at the element with the lowest tabindex
value, and work through the increments. Only then will the tab order take in the remaining elements for which no tabindex has been set. As such, great care must be taken to ensure that adding a tabindex
doesn’t harm the usability of the page as a whole.
如果将tabindex
设置在页面上的任何位置(即使是第百个链接或第五十个窗体控件),则制表符顺序将从具有最低tabindex
值的元素开始,并逐步进行。 只有这样,制表符顺序才会接受未设置tabindex的其余元素。 因此,必须tabindex
小心,以确保添加tabindex
不会损害整个页面的可用性。
If the disabled attribute is set on an element which has a tabindex
, that tabindex
will be ignored.
如果将禁用属性设置在具有tabindex
的元素上,则该tabindex
将被忽略。
例 (Example)
The tabindex
is set to "3"
for the link below:
以下链接的tabindex
设置为"3"
:
<p>You can try our <a href="cakes.html" tabindex="3">lovely
range of cakes</a>.</p>
值 (Value)
This attribute can take any numeric value.
此属性可以采用任何数值。
tabindex属性