可能重复:
对于匹配的集合中的每个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>在这种情况下,我只希望第一个被选中,而不是两者都选择。
发布于 2011-09-28 15:43:46
在过去,我也遇到过这样的问题,并且解决了这样的问题。
$(selectorOrJquery).find('select').andSelf().filter('select')
.find('option.placeholder, option[value=""]').eq(0);发布于 2011-09-28 15:43:30
这将返回select的第一个选项,该选项要么为空,要么具有类占位符。
$("select option:first").filter(":empty,.placeholder")发布于 2011-09-28 15:43:40
只需使用逗号,这是一个有效的CSS/。
$(selectorOrJquery).find('select').andSelf().filter('select')
.find('(option.placeholder, option[value=""]):first)https://stackoverflow.com/questions/7585798
复制相似问题