<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script>
var e=new Array();
e['北京']=["定海",'门头沟','房山','大兴','顺义'];
e['湖南']=['永州','长沙','益阳','邵阳','株洲'];
e['湖北']=['武汉','宜昌','襄樊','黄石','荆门'];
e['河南']=['郑州','开封','洛阳','平顶山','安阳'];
function initSheng(){ //初始化
var d=document.getElementById("sheng");
for(var index in e){
var option=document.createElement("option");//创建元素
option.text=index;
option.value=index;
d.options.add(option);
}
}
function initShi(){
var em=document.getElementById("shi");
em.options.length=0;//清除列表项
var c=document.getElementById("sheng").value;//获取省份
for (var index in e[c]){
var option=document.createElement("option");
option.text=e[c][index];
option.value=e[c][index];
em.options.add(option);
}
}
</script>
</head>
<body onload="initSheng(),initShi()">
<p>所在城市:</p>
<select id="sheng" onchange="initShi()"></select>
<select id="shi"></select>
</body>
</html>