2016-07-05 JavaScript实现省份城市二级联动
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2016-07-05 JavaScript实现省份城市二级联动相关的知识,希望对你有一定的参考价值。
简介:利用JavaScript实现省份城市二级联动
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta charset="UTF-8">
<title>New Document </title>
<script language="javascript" type="text/javascript">
var city=[
["北京","天津","上海","重庆"],
["南京","苏州","南通","常州"],
["福州","福安","龙岩"],
["广州","潮阳","潮州","澄海"],
["兰州","白银","定西","敦煌"]
];
function getCity(){
var sltProvince=document.getElementById("province");
var sltCity=document.getElementById("city");
var provinceCity=city[sltProvince.selectedIndex-1];
sltCity.length=1;//重要
for(var i=0;i<provinceCity.length;i++){
sltCity[i+1]=new Option(provinceCity[i],provinceCity[i]);//Option(text,value)
}
}
</script>
</head>
<body>
<form action="somepage.asp" name=theForm">
<select name="province" id="province" onchange="getCity()">
<option value="0">请选择所在省份</option>
<option value="直辖市">直辖市</option>
<option value="江苏省">江苏省</option>
<option value="福建省">福建省</option>
<option value="广东省">广东省</option>
<option value="甘肃省">甘肃省</option>
</select>
<select id="city" name="city">
<option value="0">请选择所在城市</option>
</select>
</form>
</body>
</html>
以上是关于2016-07-05 JavaScript实现省份城市二级联动的主要内容,如果未能解决你的问题,请参考以下文章
[JavaScript 刷题] 搜索 - 省份数量, leetcode 547
学习aiax(javascript)--省份-城市二级下拉联动(POST方式)