javascript 根据tabindex查找元素

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

find element based on tabindex

javascriptjquerytabindex

提问by amateur

Using jquery or javascript, how can I find the input element in the DOM that has a particular tabindex set to it, eg.

使用 jquery 或 javascript,如何在 DOM 中找到设置了特定 tabindex 的输入元素,例如。

<input id="txtInput" type="text" maxlength="5" tabindex="7">

I would want this element returned if I was searching for the element with tabindex = 7.

如果我正在搜索 tabindex = 7 的元素,我希望返回这个元素。

回答by Nalum

You can get it with the following jQuery

您可以使用以下 jQuery 获取它

$('input[tabindex=7]')

回答by Jakub Roztocil

You can find the element by an attribute selector:

您可以通过属性选择器找到该元素:

$('[tabindex=7]')

回答by pimvdb

With the attribute selector:

使用属性选择器

$("[tabindex=7]") // all elements with tabindex=7