2010-01-01 68 views
19

在一个HTML表单中,我有INPUT文本框,后跟一个链接,然后是另一个INPUT文本框。我想从tabindex属性/ Tab顺序删除链接:Javascript/JQuery从tabindex中删除

<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> 

的选项卡顺序是field,链接1,场2,我希望它是FIELD1,FIELD2没有tabindex属性/顺序在所有链接1。除了通过tabindex属性重新排序之外,还有什么办法可以从tab键中删除link1吗?

回答

34

你可以用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> 

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

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

它的工作原理,它解决了一个问题,我有,但它证实/是交叉浏览器兼容。 W3说tabindex应该介于0和32767之间..? – pnichols 2010-09-21 20:43:02

+3

它使用过渡文档类型(我没有检查任何其他文档)进行验证,并在FF,safari,chrome,opera和IE 6,7,8中工作。 – Jage 2010-09-22 19:07:16