Html 按 tab 时跳过输入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13435217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:56:19  来源:igfitidea点击:

Skip input when press tab

html

提问by eshellborn

I have a form where there are three input boxes with three drop down select tags beside them. I want to be able to press the tab key and go from one input to another, but you have to press it twice because it goes to the drop down menu after the input box. Is there a way I can make it "skip over" the drop down menu and go right to the next input box when you press tab?

我有一个表单,其中有三个输入框,旁边有三个下拉选择标签。我希望能够按下 Tab 键并从一个输入转到另一个输入,但是您必须按两次它,因为它会在输入框之后进入下拉菜单。有什么方法可以让它“跳过”下拉菜单并在按下 Tab 键时直接转到下一个输入框?

采纳答案by zzzzBov

You can specify the tabbing order explicitly by setting the [tabindex]attribute:

您可以通过设置[tabindex]属性来显式指定跳转顺序:

without [tabindex]:没有[tabindex]
<input type="text" />     <!-- first -->
<input type="checkbox" /> <!-- second -->
<select>...</select>      <!-- third -->
with [tabindex]:[tabindex]
<input type="text" tabindex="1" />      <!-- first -->
<input type="checkbox" tabindex="3" /> <!-- third -->
<select tabindex="2">...</select>      <!-- second -->

回答by el Dude

tabindex=0property makes inputs skippable in case when other inputs have tabindex values above zero.

tabindex=0属性使输入可跳过,以防其他输入的 tabindex 值高于零。

tabindex="-1"makes inputcompletely skippable

tabindex="-1"使input完全可跳过