Home > php教程 > php手册 > js城市选择级联|js城市选择联动|javascript

js城市选择级联|js城市选择联动|javascript

WBOY
Release: 2016-06-06 19:34:16
Original
1492 people have browsed it

这个是从百度个人中心找到的省市区城市级联JS基础城市数据 http://pr.bdimg.com/static/princess/js/setting_basic_f2b6cf89.js 如果想直接使用,可以下载弄好的cityData.js,请稳步到代码片段。 jQuery PHP select id="prov" onchange="getCity(this.value);

这个是从百度个人中心找到的省市区城市级联JS基础城市数据
http://pr.bdimg.com/static/princess/js/setting_basic_f2b6cf89.js
如果想直接使用,可以下载弄好的cityData.js,请稳步到代码片段。 jQuery PHP
<select id="prov" onchange="getCity(this.value);"></select>
<select id="city" onchange="getTown(this.previousElementSibling.value, this.value);"></select>
<select id="town"></select>

<script type="text/javascript" src="cityData.js"></script>

<script type="text/javascript">
	var porv='',city='',town='';
	var $ = function (id){return document.getElementById(id);}
	var c = cityData();
	var lenP = c.length;
	for(i=0; i<lenP; i++){
		prov += '<option value="' + i + '">' + c[i].name + '</option>';	
	}
	$('prov').innerHTML = prov;
	var getCity = function (f){
		var lenC = c[f].sub.length;
		for(j=0; j<lenC; j++){
			city += '<option value="' + j + '">' + c[f].sub[j].name + '</option>';		
		} 
		$('city').innerHTML = city;
	}
	var getTown = function (t, m){
		var lenT = c[t].sub[m].sub.length; 
		for(k=0; k<lenT; k++){
			town += '<option value="' + k + '">' + c[t].sub[m].sub[k].name + '</option>';		
		} 
		$('town').innerHTML = town;
	}
</script>
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template