【发布时间】:2013-05-20 07:07:50
【问题描述】:
我正在尝试创建一个简单的函数,当一个 div 中的所有下拉框都被选中时,它会告诉我。问题似乎是过滤器没有选择任何东西,所以长度总是为 0。知道会发生什么吗?到目前为止,这是我所拥有的:
jQuery
$('.month, .year').change(function () {
var $this = $(this);
var $empty = $this.parent().parent().find('.month, .year').filter('[value=""]').length;
if ($empty == 0) {
alert('there are no empty dropdowns');
}
});
HTML
<form class="date_catcher">
<div style="display:inline;" class="start">
<select class='input-small month' name='month'>
<option value='' selected='selected'>---</option>
<option value='0'>Jan</option>
</select>
<select class='input-small year' name='year'>
<option value='' selected='selected'>----</option>
<option value="2012">2012</option>
</select>
</div>
<div style="display:inline;" class="end">
<select class='input-small month' name='month'>
<option value='' selected='selected'>---</option>
<option value='0'>Jan</option>
</select>
<select class='input-small year' name='year'>
<option value='' selected='selected'>----</option>
<option value="2012">2012</option>
</select>
</div>
</form>
感谢您的帮助!
【问题讨论】:
-
.month和.year是选择元素而不是选项。注意select元素没有value属性。
标签: jquery drop-down-menu filter