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