根据tabindex查找元素

发布于 2024-11-26 20:36:32 字数 201 浏览 3 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

执手闯天涯 2024-12-03 20:36:32

您可以使用以下 jQuery 获取它

$('input[tabindex=7]')

You can get it with the following jQuery

$('input[tabindex=7]')
晨曦÷微暖 2024-12-03 20:36:32

使用属性选择器

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

With the attribute selector:

$("[tabindex=7]") // all elements with tabindex=7
自此以后,行同陌路 2024-12-03 20:36:32

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

$('[tabindex=7]')

You can find the element by an attribute selector:

$('[tabindex=7]')
终难遇 2024-12-03 20:36:32

仅使用 JavaScript:

document.querySelectorAll("input[tabindex='7']");

如果您想要所有元素,而不仅仅是输入,其 tabindex 属性为 7:

document.querySelectorAll("[tabindex='7']");

但是, MDN 建议避免 tabindex 值大于零,因为它可能会令人困惑,特别是对于那些使用屏幕阅读器的人。

Just using JavaScript:

document.querySelectorAll("input[tabindex='7']");

And if you want all elements, not just inputs, with a tabindex attribute of seven:

document.querySelectorAll("[tabindex='7']");

However, MDN recommends avoiding tabindex values greater than zero as it may be confusing, especially for those using screen readers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文