编辑:
演示: http://jsfiddle.net/53GKh/6/
我在HTML中有2个下拉菜单:
首先是获得汽车品牌:(工作正常)
<form action="car-list.php" method="get">
<select name="search" id="main_list" >
<option value="BMW"<?php if ($_GET['search']== 'BMW') {echo "selected='selected'"; } ?>>Bmw</option>
</select>
</form>
用户选择品牌后,第二个下拉菜单将被激活&#39;选择汽车的型号:
<select name="model" id="brand" class="secondary">
<option disabled selected> Kies </option>
</select>
激活&#39;使用以下JS代码的第二个下拉菜单:
$(function() {
var sel, i,
list = ['aixman', 'alfaromeo', 'bmw'],
aixman = ['Aixman'],
alfaromeo = ['33', '75'],
bmw= ['1-serie','3-serie','4-serie','5-serie','6-serie'],
astonmartin = ['Cygnet', 'DB7'],
dev_default = '<option value="default" selected>Kies</option>',
sel_brand = $('#brand');
sel_version = $('#version');
$('select').change(function() {
switch (this.id) {
case 'main_list':
sel_brand.find('option').remove();
sel_brand.append(dev_default);
sel_brand.show();
if (this.value == 'BMW') {
for (i = 0; i < bmw.length; i++) {
$("#brand").append(
'<option value="' + bmw[i] + '">' + bmw[i] + '</option>'
);
}
}
break;
}
});
}); //END document.ready()
我刚刚更新了我的JS代码:如何在提交/刷新页面后回显我的第二个Dropbox菜单的选定值?