jQuery选择器错误?组合选择器与简单选择器&找() [英] jQuery selector bug? composed selector vs. simple selector & find()

查看:93
本文介绍了jQuery选择器错误?组合选择器与简单选择器&找()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况有些尴尬...我有这样的事情:

Something is very awkward about my situation... i have something like this:

<div id="selector">
   <input type='radio' />
   <input type='radio' />
   <input type='radio' />
</div>

如果我使用$("#selector input[type=radio]"),则会找到所有三个元素,但是如果我使用$("#selector").find("input[type=radio]")甚至是find("input"),则只会找到第一个元素.

if I use $("#selector input[type=radio]") all three elements are found, but if I use $("#selector").find("input[type=radio]") or even find("input") only the first one is found.

这是jQuery中的错误吗?我不能正确使用find()吗?

Is this a bug in jQuery? Am I not using find() properly?

澄清:我想使用find()来获取所有输入,但是我尝试执行的任何操作都只能找到第一个.

Clarification : I want to use find() to get all the inputs, but anything I try finds only the first one.

我正在使用jquery 1.3.2

edit: i'm using jquery 1.3.2

推荐答案

您真正想要的是:

$("#selector > :radio")

关于为什么只得到一个的原因,我需要查看正在运行的实际代码,因为find()不止于一个,而且会找到所有匹配项,因此可能是您使用它的方式之后就是问题了.

As for why you're getting only one, I'd need to see the actual code that's being run because find() doesn't stop at one and will find all matches so it may be how you're using it afterwards that is the issue.

这篇关于jQuery选择器错误?组合选择器与简单选择器&amp;找()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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