<script type="text/javascript">
function selcity(){
var arr = [["--選擇城市--"],["海定區(qū)","東城區(qū)","西城區(qū)","朝陽(yáng)區(qū)"],["濟(jì)南","青島","日照","威海"],
["長(zhǎng)沙","郴州","岳陽(yáng)","株洲"],["廣州","深圳","惠州","東莞"]];
var index = document.getElementById("selID").selectedIndex;
var subNode = document.getElementById("subID");
var citys = arr[index];
subNode.options.length = 0; //清空之前選項(xiàng)
for(var x=0;x<citys.length;x++){
var optNode = document.createElement("option");
optNode.innerText = citys[x];
subNode.appendChild(optNode); //選擇添加到子選項(xiàng)中
}
}
</script>
<style type="text/css">
</style>
</head>
<body>
<select id="selID" onchange="selcity()">
<option>--選擇省市--</option>
<option>北京</option>
<option>山東</option>
<option>湖南</option>
<option>廣東</option>
</select>
<select id="subID">
<option>--選擇城市--</option>
</select>
</body>
附
該文章于2017年8月7日于CSDN上首次發(fā)表糙捺,2017年12月24日搬家至此诫咱!