Javascript/JQuery 从 tabindex 中删除

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1987927/
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-22 22:15:45  来源:igfitidea点击:

Javascript/JQuery remove from tabindex

javascriptjqueryhtmltabindex

提问by leepowers

On an HTML form I have INPUT text box followed by a link, then followed by another INPUT text box. I want to remove the link from the tabindex / tab order:

在 HTML 表单上,我有 INPUT 文本框,后跟一个链接,然后是另一个 INPUT 文本框。我想从 tabindex / tab order 中删除链接:

<p>
<input type="text" name="field1" id="field1" value="" />
<a href="..a url.." id="link1">more info</a>
</p>

<p>
<input type="text" name="field2" id="field2" value="" />
</p>

The tab order is field1, link1, field2 and I want it to be field1, field2 without link1 in the tabindex / order at all. Aside from reordering via the tabindexattribute, is there any way to remove link1 from tabbing altogether?

选项卡顺序是 field1、link1、field2,我希望它是 field1、field2,在 tabindex/order 中根本没有 link1。除了通过tabindex属性重新排序之外,是否有任何方法可以从选项卡中完全删除 link1?

回答by Jage

You can achieve this with html:

您可以使用 html 实现此目的:

<p>
<input type="text" name="field1" id="field1" value="" />
<a href="#" id="link1" tabindex="-1">more info</a>
</p>

<p>
<input type="text" name="field2" id="field2" value="" />
</p>

You could also use jquery to do this:

你也可以使用 jquery 来做到这一点:

$('#link1').prop('tabIndex', -1);