jQuery - 重复ID的选择器 [英] jQuery - Selector for duplicate ID's

查看:166
本文介绍了jQuery - 重复ID的选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,其中包含表单元素的重复ID。问题是我根据切换单独显示元素。因此,两个ID都不会同时显示。

I have a page with duplicate ID's for a form element. The catch is I the elements show up separately based on a toggle. So both ID's never show up simultaneously.

但是当我对该元素进行表单验证时,它总是选择代码中最后显示的元素(即使它隐藏了)。

However when I do form validation on that element, it always selects the element displayed last in the code (even if its hidden).

是否有选择器可以选择可见的重复ID?

Is there a selector to select the visible duplicate ID?

我尝试了以下但是没有可用:

I've tried the following but to no avail:

$('#my_element:visible').val();


推荐答案

由于关于此前提的无数其他问题将告诉我们在这种情况下,你不能使用ID选择器;你必须使用 $('div [id = foo]')之类的东西来找到它。

As the myriad of other questions about this premise will tell you, you cannot use the ID selector # in this case; you have to use something like $('div[id=foo]') to find it.

这篇关于jQuery - 重复ID的选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆