用js做省市级联菜单,用二维数组实现,不知为何就是无法实现,求大神点拨,下面是代码:
<form name="form1" method="post" action="">
<select id="sheng" onChange="changecity();"><script type="text/javascript">fillsheng();</script>
</select>
<select id="shi">
<option value="0000">--请选择城市--</option>
</select>
</form>
***********js代码
var provinces = new Array(
new Array("01","北京"),
new Array("02","安徽"),
new Array("03","湖北"),
new Array("04","江苏")
);
var cities = new Array(
new Array("0102","海淀"),
new Array("0103","朝阳"),
new Array("0202","芜湖"),
new Array("0204","马鞍山"),
new Array("0301","武汉"),
new Array("0303","荆州"),
new Array("0401","南京"),
new Array("0402","苏州")
);
function fillsheng(){
var sheng = document.getElementById("sheng");
for(var i=0;i<provinces.length;i++){
var option = new Option(provinces[i][1],provinces[i][0]);
sheng.add(option,null);
}
sheng.options[0].selected = true;
}
function changecity(){
var sheng = document.getElementById("sheng");
var procode = sheng.value;
var city = document.getElementById("shi");
city.options.length = 0;
city.add(new Option("选择城市","0000"),null);
for(var i=0;i<cities.length;i++){
if(cities[i][0].substring(0,2) == procode)
city.add(new Option(cities[i][1],cities[i][0]),null);
city.options[0].selected = true;
}
}