JQuery: Determine which SELECT among the children has changed
I have 3 grouped select Month, Day and Year... I am changing the contents of Day SELECT based on the values of Month and Year SELECTs. example is I will make the options in Day up to 28 if the Month is February etc. I want a function which runs if the user changed the value of Month or Year but ignore if the Day is selected. I have this function
$("#ui-1 .ui-select").children().change(
function(){
...if the Day select has been changed exit this function
});
});
I have this HTML....
<div id="ui-1">
<div class="ui-select" data-role="controlgroup" data-type="horizontal" >
<select data-native-menu="false" data-inline="true" data-icon="arrow-d" data-iconpos="right" id="Datepicker_0_0" name="Datepicker_0_0">
<option value="1">January</option>
<option value="2">February</option>
.... and so on
</select>
<select data-native-menu="false" data-inline="true" data-icon="arrow-d" data-iconpos="right" id="Datepicker_0_1" name="Datepicker_0_1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
... up to here
<option value="31">31</option>
开发者_开发问答</select>
<select data-native-menu="false" data-inline="true" data-icon="arrow-d" data-iconpos="right" id="Datepicker_0_2" name="Datepicker_0_2">
<option value="1975">1975</option>
<option value="1976">1976</option>
<option value="1977">1977</option>
...up to here
<option value="2050">2050</option>
</select>
</div>
</div>
this
points to the element from which the event originated, so you could use if(this.id == 'Datepicker_0_1') return;
$("#ui-1 .ui-select").children().change(
function(){
if(this.id == "Datepicker_0_0") return;
//rest of code
});
});
Check whether the id
attribute of the select
element equals "Datepicker_0_0"
(that's the identifier of you "Day" select element).
You should be able to specify either an id
or an name
for each select.
You can figure out which select it it by $(this).attr('id')
or 'name'
.
function(){
if( $( this ).attr( 'name' ) == 'Datepicker_0_1' )
return;
});
精彩评论