根据tabindex查找元素
使用 jquery 或 javascript,如何在 DOM 中找到设置了特定 tabindex 的输入元素,例如。
<input id="txtInput" type="text" maxlength="5" tabindex="7">
如果我正在搜索 tabindex = 7 的元素,我希望返回该元素。
Using jquery or javascript, how can I find the input element in the DOM that has a particular tabindex set to it, eg.
<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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用以下 jQuery 获取它
You can get it with the following jQuery
使用属性选择器:
With the attribute selector:
您可以通过属性选择器找到该元素:
You can find the element by an attribute selector:
仅使用 JavaScript:
如果您想要所有元素,而不仅仅是输入,其 tabindex 属性为 7:
但是, MDN 建议避免 tabindex 值大于零,因为它可能会令人困惑,特别是对于那些使用屏幕阅读器的人。
Just using JavaScript:
And if you want all elements, not just inputs, with a tabindex attribute of seven:
However, MDN recommends avoiding tabindex values greater than zero as it may be confusing, especially for those using screen readers.