<script type="text/javascript">
function selcity(){
var arr = [["--選擇城市--"],["海定區","東城區","西城區","朝陽區"],["濟南","青島","日照","威海"],
["長沙","郴州","嶽陽","株洲"],["廣州","深圳","惠州","東莞"]];
var index = document.getElementById("selID").selectedIndex;
var subNode = document.getElementById("subID");
var citys = arr[index];
subNode.options.length = 0; //清空之前選項
for(var x=0;x<citys.length;x++){
var optNode = document.createElement("option");
optNode.innerText = citys[x];
subNode.appendChild(optNode); //選擇添加到子選項中
}
}
</script>
<style type="text/css">
</style>
</head>
<body>
<select id="selID" οnchange="selcity()">
<option>--選擇省市--</option>
<option>北京</option>
<option>山東</option>
<option>湖南</option>
<option>廣東</option>
</select>
<select id="subID">
<option>--選擇城市--</option>
</select>
</body>