<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>省市级联</title>
<script type="text/javascript">
function chooseCity(){
var sheng = document.getElementById("sheng").value;
var cityArray = new Array();
cityArray["陕西省"] = ["西安市","渭南市","宝鸡市","汉中市","延安市"];
cityArray["河南省"] = ["郑州市","开封市","焦作市","新乡"];
cityArray["广东省"] = ["深圳市","广州市","东莞市"];
document.getElementById("city").options.length = 1;
for(var index in cityArray[sheng]){
var option = new Option(cityArray[sheng][index] , cityArray[sheng][index]); //逗号前的为option的内容,后面的是value的值
document.getElementById("city").options.add(option);
}
}
</script>
</head>
<body>
<select id="sheng" οnchange="chooseCity()">
<option value="">--请选择省份--</option>
<option value="陕西省">陕西省</option>
<option value="河南省">河南省</option>
<option value="广东省">广东省</option>
</select>
<select id="city" >
<option value="">--请选择城市--</option>
</select>
</body>
</html>