第一次写博客,如有雷同,纯属抄袭!见谅, 见谅!
放在body里面的代码
<div class="">
<select id="born" name="born" class="" onChange="getCity(this.options[this.selectedIndex].value)">
<option value="请选择">请选择</option>
<option value="上海市及随迁子女">上海市及随迁子女</option>
<option value="常州市">常州市</option>
<option value="其它">其它</option>
</select>
</div>
<div class="" id="nameInfor_two">
<select name="" class="" id="city" runat="server">
<option>请选择</option>
</select>
</div>
<div class="" id="nameInfor_three" style="display: none;">
<select name="" class="" id="city1" runat="server" onChange="getCity2(this.options[this.selectedIndex].value)">
<option value="请选择">请选择</option>
<option value="广州市">广州市</option>
<option value="常州市">常州市</option>
<option value="其它">其它</option>
</select>
<select name="" class="" id="city2" runat="server">
<option>请选择</option>
</select>
</div>
<script>里面代码
<script language="javascript" type="text/javascript">
//定义 城市 数据数组
cityArray = new Array();
cityArray[0] = new Array("上海市及随迁子女", "静安区|长宁区|徐汇区|杨浦区|虹口区|普陀区|宝山区|闵行区|嘉定区");
cityArray[1] = new Array("常州市", "钟楼区|天宁区|武进区|无人区");
cityArray[2] = new Array("其它", "其它");
cityArray[3] = new Array("请选择", "请选择");
cityArray1 = new Array();
cityArray1[0] = new Array("广州市", "静安区|长宁区|徐汇区|杨浦区|虹口区|普陀区|宝山区|闵行区|嘉定区");
cityArray1[1] = new Array("常州市", "钟楼区|天宁区|武进区|无人区");
cityArray1[2] = new Array("其它", "其它");
cityArray1[3] = new Array("请选择", "请选择");
function getCity(currProvince) {
//当前 所选择 的 省
var currProvince = currProvince;
var i, j, k;
//清空 城市 下拉选单
document.all.city.length = 0;
for(i = 0; i < cityArray.length; i++) {
//得到 当前省 在 城市数组中的位置
if(cityArray[i][0] == currProvince) {
//得到 当前省 所辖制的 地市
var tmpcityArray = cityArray[i][1].split("|")
for(j = 0; j < tmpcityArray.length; j++) {
//填充 城市 下拉选单
document.all.city.options[document.all.city.length] = new Option(tmpcityArray[j], tmpcityArray[j]);
}
document.getElementById("nameInfor_two").style.display = "block";
document.getElementById("nameInfor_three").style.display = "none";
} else if(cityArray[2][0] == currProvince) {
document.getElementById("nameInfor_two").style.display = "none";
document.getElementById("nameInfor_three").style.display = "block";
}
}
}
function getCity2(ob) {
var ob = ob;
var x, y, z;
document.all.city2.length = 0;
for(i = 0; i < cityArray1.length; i++) {
if(cityArray1[i][0] == ob) {
//得到 当前省 所辖制的 地市
var tmpcityArray = cityArray1[i][1].split("|")
for(j = 0; j < tmpcityArray.length; j++) {
//填充 城市 下拉选单
document.all.city2.options[document.all.city2.length] = new Option(tmpcityArray[j], tmpcityArray[j]);
}
}
}
}
</script>