Jquery selectedIndex选择器(检查selectedIndex数组是否已selectedIndex>;0)

Jquery selectedIndex选择器(检查selectedIndex数组是否已selectedIndex>;0),jquery,select,jquery-selectors,selectedindex,Jquery,Select,Jquery Selectors,Selectedindex,与其在元素数组上编写一个临时布尔值$.each(),并查找一个人的属性('selectedIndex')>0,我想做如下操作: $('select[id^="idPrefixForTheArrayOfSelects-"][selectedIndex="0"]').length == 0 但它不起作用 是否可以按值、selectedIndex等进行选择?您可以这样做- $('select[id^="idPrefixForTheArrayOfSelects-"]').filter(function

与其在
元素数组上编写一个临时布尔值
$.each()
,并查找一个人的
属性('selectedIndex')>0
,我想做如下操作:

$('select[id^="idPrefixForTheArrayOfSelects-"][selectedIndex="0"]').length == 0
但它不起作用

是否可以按值、selectedIndex等进行选择?

您可以这样做-

$('select[id^="idPrefixForTheArrayOfSelects-"]').filter(function(){
 return this.selectedIndex === 0;
}).length == 0
你可以这样做-

$('select[id^="idPrefixForTheArrayOfSelects-"]').filter(function(){
 return this.selectedIndex === 0;
}).length == 0

selectedIndex
是一个属性,而不是select上的属性。您拥有的是一个属性选择器。阅读更多
selectedIndex
是一个属性,而不是select上的属性。您拥有的是一个属性选择器。读得更美!对我的文本框/textarea数组使用了相同的东西,带有
$(this).val()
。泰!美丽的!对我的文本框/textarea数组使用了相同的东西,带有
$(this).val()
。泰!