select文本框架(change事件)改变另外一个select的值

$('select[name=adults]').bind('change', function() {
var $value = $(this).val();
if ($value >= 1) {
var html = '';
for (i = 1; i <= $value; i++) {
html = html + '<option value="' + i + '">' + i + '</option>';
}
$('select[name=infants] option').each(function() {
if ($(this).val() > 0) {
$(this).remove();
}
});
$(html).appendTo('select[name=infants]')
} else {
var html = '';
html = html + '<option value="0">0</option>';
html = html + '<option value="1">1</option>';
$(html).appendTo('select[name=infants]')
}
});

原文地址:https://www.cnblogs.com/hgj123/p/3725192.html