--- id: 587d7790367417b2b2512ab1 title: Use tabindex to Specify the Order of Keyboard Focus for Several Elements challengeType: 0 videoUrl: '' localeTitle: 使用tabindex指定多个元素的键盘焦点顺序 --- ## Description
tabindex属性还指定元素的确切Tab键顺序。当属性的值被设置为1或更高的正数时,可以实现这一点。设置tabindex =“1”将首先将键盘焦点放在该元素上。然后循环显示指定tabindex值(2,3等)的序列,然后移至默认值和tabindex="0"项。重要的是要注意,当以这种方式设置Tab键顺序时,它会覆盖默认顺序(使用HTML源)。这可能会使期望从页面顶部开始导航的用户感到困惑。在某些情况下,这种技术可能是必要的,但就可访问性而言,在应用之前要小心。这是一个例子: <div tabindex="1">I get keyboard focus, and I get it first!</div> <div tabindex="2">I get keyboard focus, and I get it second!</div>
## Instructions
Camper Cat在他的Inspirational Quotes页面上有一个搜索字段,他计划使用CSS在右上角定位。他希望搜索input并将input表单控件提交为Tab键顺序中的前两项。将tabindex属性设置为“1”到搜索inputtabindex属性设置为“2”到提交input
## Tests
```yml tests: - text: 您的代码应该向搜索input标记添加tabindex属性。 testString: 'assert($("#search").attr("tabindex"), "Your code should add a tabindex attribute to the search input tag.");' - text: 您的代码应该向提交input标记添加tabindex属性。 testString: 'assert($("#submit").attr("tabindex"), "Your code should add a tabindex attribute to the submit input tag.");' - text: 您的代码应将搜索input标记上的tabindex属性设置为值1。 testString: 'assert($("#search").attr("tabindex") == "1", "Your code should set the tabindex attribute on the search input tag to a value of 1.");' - text: 您的代码应将submit input标记上的tabindex属性设置为值2。 testString: 'assert($("#submit").attr("tabindex") == "2", "Your code should set the tabindex attribute on the submit input tag to a value of 2.");' ```
## Challenge Seed
```html

Even Deeper Thoughts with Master Camper Cat

Inspirational Quotes

“There's no Theory of Evolution, just a list of creatures I've allowed to live.”
- Chuck Norris

“Wise men say forgiveness is divine, but never pay full price for late pizza.”
- TMNT

```
## Solution
```js // solution required ```