如何在jquery中跳过与其他标签具有相同类名的标签

发布于 2024-07-29 11:24:32 字数 262 浏览 1 评论 0原文

如何跳过 jquery 中与其他标签具有相同类名的一个标签,两者都会显示,因此请帮助如何使用 jquery 跳过一个标签

<label for="myCb1">test1</label>
<label for="myCb1">test</label>
<input type="checkbox" id="myCb1" value="1" />

当我尝试调用 myCb1 的标签时,

How to skip one label having same class name of other in jquery

<label for="myCb1">test1</label>
<label for="myCb1">test</label>
<input type="checkbox" id="myCb1" value="1" />

when i try to invoke the label of myCb1 both are display so please help how to skip one label using jquery

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

遇见了你 2024-08-05 11:24:33

您想使用 :eq 伪选择器作为这样:

$("label[for='myCb1']:eq(1)")

:eq 允许您指定要返回的已找到元素的索引。 索引是从零开始(这意味着第一个元素将是索引0)。

jQuery 文档::eq 伪选择器

You want to use the :eq pseudo-selector as such:

$("label[for='myCb1']:eq(1)")

:eq allows you to specify the index of the found elements that you want to return. The index is zero-based (which means that the first element will be index 0).

jQuery Docs: :eq pseudo-selector

九局 2024-08-05 11:24:33

$('.class:first-child')

这是如果它们像您刚才描述的那样彼此相邻。

$('.class:first-child')

This is if they are right next to each other like you just described.

绳情 2024-08-05 11:24:33

要么给它们一个 id 来唯一标识它们,要么您可以使用选择器,例如:

$("label[for=myCb1]:eq(0)") // Only selects the first label
$("label[for=myCb1]:eq(1)") // Only selects the second label

Either give them an id to uniquely identify them, or you can use a selector such as:

$("label[for=myCb1]:eq(0)") // Only selects the first label
$("label[for=myCb1]:eq(1)") // Only selects the second label
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文