我有三个下拉菜单:
<div class = "form=group">
<select class = "selecter" id = "day"><option>1<option><option>2</option></select>
<select class = "selecter" id = "month"><option>1<option><option>2</option></select>
<select class = "selecter" id = "year"><option>1<option><option>2</option></select>
</div>
我想检测是否所有三个字段都已选中,以便验证日期。我尝试了以下方法:
$('.selecter').on('change', function() {
console.log("Something is changed!");
});
但每次降落都会起火。如何将每个函数添加到其中,以便在所有选择器类都更改后进行检测?我也可以在选择一个后点击下一个下拉列表?感谢所有
在易于检查更改的选择中添加一个类或添加其他内容,并将更改的选择数与选择数进行比较,以了解是否所有选择都已更改:
var selects = $('.selecter').length;
$('.selecter').on('change', function() {
$(this).addClass('changed');
if ( $('.changed').length == selects ) {
// someone changed all three selects ?
}
});