【问题标题】:selectedIndex selector (check if array of selects have selectedIndex > 0) [closed]selectedIndex 选择器(检查选择数组是否有 selectedIndex > 0)[关闭]
【发布时间】:2013-05-20 07:46:46
【问题描述】:

我不想在<select> 元素的数组上写一个临时布尔值$.each() 并查找是否是prop('selectedIndex') > 0,我想做类似的事情:

$('select[id^="idPrefixForTheArrayOfSelects-"][selectedIndex="0"]').length == 0

但它不起作用。

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

【问题讨论】:

标签: jquery select jquery-selectors selectedindex


【解决方案1】:

你可以这样做 -

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

【讨论】:

  • 漂亮!使用$(this).val() 对我的文本框/文本区域数组使用相同的东西。太棒了!
猜你喜欢
  • 1970-01-01
  • 2018-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-25
  • 2021-04-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多