JS实现的省份级联实例代码
投稿:shangke
这是从本人以前博客带过来的,感觉这个还蛮实用,代码分享下:
province.html:
<html>
<head>
<title>省份与省市级联</title>
</head>
<script language="javascript" src="province.js" type="text/javascript" charset="gb2312"></script>
</script>
<body onload='getProvince()'>
<div id='province'><select><option>省份</option></select></div>
<div id='city'><select><option>城市</option></select></div>
</boydy>
</html>
province.js:
function getRegion()
{
document.getElementById("city").innerHTML="";
var provinces=document.getElementById("provinces");
var prov=provinces[provinces.selectedIndex].value;
var str="<select>";
for(var i=0;i<city[prov].length;i++)
{
str=str+"<option>"+city[prov][i]+"</option>";
}
str=str+"</select>";
document.getElementById("city").innerHTML=str;
}
function getProvince()
{ var strs="<select onchange='getRegion()' id='provinces'><option></option>";
for(var i=0;i<=33;i++)
{
strs=strs+"<option value="+i+">"+city[i][0]+"</option>";
}
strs=strs+"</select>";
document.getElementById('province').innerHTML=strs;
}
[/code]