答案 0 :(得分:0)
试试这个..
$("#select1").change(function () {
if ($(this).data('options') == undefined) {
/*Taking an array of all options-2 and
kind of embedding it on the select1*/
$(this).data('options', $('#select2 option').clone());
}
var id = $(this).val();
var options;
if( id === '') {
options = $(this).data('options');
}
else {
options = $(this).data('options').filter('[value=' + id + ']');
}
$('#select2').html(options);
}).change();
<强> Check Fiddle 强>
答案 1 :(得分:0)
尝试这种方式: -
var id = this.value;//Get the value of the option.
var options = $(this).data('options'); //get all the saved options.
if (id) { //if there is value then filter it out
options = $(this).data('options').filter('[value=' + id + ']');
}
$('#select2').html(options).prop('selectedIndex', 0); //save option and set selectedindex to first element.