jQuery/Sizzle 中有 OR 组合器吗?
可能的重复:
jQuery 或选择器?
我想为匹配集中的每个 select
找到第一个具有类 placeholder
或空值的 option
,
$(selectorOrJquery).find('select').andSelf().filter('select')
.find('(option.placeholder OR option[value=""]):first)
不幸的是,这不是有效的 sizzle (或 CSS3)语法 - 任何人都知道是否有是执行此操作的有效方法选择器?
显然我可以编写程序代码来为我找到这个,但我希望有一些更流畅的
编辑: 澄清一下,我认为逗号不起作用。想象一下以下情况
<select>
<option class="placeholder" value="0">Select Something</option>
<option value="">Legitimate option that gets handled in JS</value>
</select>
在这种情况下我只想要第一个选择的,而不是两个
Possible Duplicate:
jQuery OR Selector?
I would like to for each select
in the matched set find the first option
that either has a class placeholder
or an empty value something along the lines of
$(selectorOrJquery).find('select').andSelf().filter('select')
.find('(option.placeholder OR option[value=""]):first)
That is unfortunately not a valid sizzle (or CSS3) syntax - anyone know if there is a valid way to do this with selectors?
Obviously I could write procedural code to find this for me, but I'm hoping for something a bit more slick
Edit:
To clarify, I do not think a comma simply works. Imagine the following
<select>
<option class="placeholder" value="0">Select Something</option>
<option value="">Legitimate option that gets handled in JS</value>
</select>
In this case I want only the first selected, NOT both
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我过去也遇到过类似的问题,并解决了类似的问题。
I have also run into an issue like this in the past and settled for something like this.
这将返回选择的第一个选项,该选项要么为空,要么具有类占位符。
This will return the first option of a select that is either empty or has a class placeholder.
只需使用逗号,这是一个有效的 CSS/jQuery 选择器。
Just use a comma, which is a valid CSS/jQuery Selector.
css OR 是逗号,所以您想要的选择器是
the css OR is the comma, so the selector you want would be