我想检查一组选择框,看看它们在单击按钮后是否发生了变化。
<select name="data[model][that]" class="location_dropdown">
<option value="value1">value 1</option>
<option value="value2">value 2</option>
<option value="value3" selected="selected">value 3</option>
</select>
<select name="data[model][that]" class="location_dropdown">
<option value="value1">value 1</option>
<option value="value2" selected="selected">value 2</option>
<option value="value3">value 3</option>
</select>
<select name="data[model][other]" class="location_dropdown">
<option value="value1" selected="selected">value 1</option>
<option value="value2">value 2</option>
<option value="value3">value 3</option>
</select>
$(document).ready(function() {
$('#update-selected-btn').click(function(){
$('.location_dropdown').each(function(){
});
});
if state hasnt changed on any drop downs alert("nothing selected")
});
显然不能使用 onchange ,因为我想在触发按钮单击时检查更改。我在考虑可能构建一组值并将它们相互检查,但想知道是否有另一种解决方案。
更新:
我确实尝试过,但语法不正确。
$('.location_dropdown').each(function(){
if ($(this + " option:selected").prop('selected') == 'selected'){
changed++;
}
});