标签:
<!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>
</head>
<body>
<select id="sheng">
<option>-请选择-</option>
</select>
<select id="city">
<option>-请选择-</option>
</select>
</body>
<script type="text/javascript">
//加载方法
onload = checkcity;
//封装方法
function checkcity(){
//获取省份的id
var sheng = document.getElementById("sheng");
//创建数组
var arr = new Array();
arr[‘江西省‘]=[‘南昌市‘,‘赣州市‘];
arr[‘河南省‘]=[‘郑州市‘,‘洛阳市‘];
//获取省份
for(var i in arr){
sheng.add(new Option(i,i),null);
}
//获取市
sheng.onchange = function(){
var sheng = document.getElementById("sheng").value;
var city = document.getElementById("city");
city.length = 0;
//迭代级联
for(var k in arr[sheng]){
city.add(new Option(arr[sheng][k],arr[sheng][k]),null);
}
}
}
</script>
</html>
标签:
原文地址:http://www.cnblogs.com/zengweiB208/p/4353615.html