首页 新闻 会员 周边 捐助

谁能给个中国省市选择的例子啊?

0
悬赏园豆:5 [已解决问题] 解决于 2012-03-20 07:51

谁能给个中国省市选择的例子啊?

最好地封装好的

tab_china的主页 tab_china | 初学一级 | 园豆:54
提问于:2012-03-19 10:24
< >
分享
最佳答案
0
收获园豆:5
dudu | 高人七级 |园豆:30948 | 2012-03-19 11:02
其他回答(2)
0
LCM | 园豆:6876 (大侠五级) | 2012-03-19 10:28
0

Demo(只添加了部分地区):

<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<meta charset="utf-8"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<style type="text/css">

</style>
<script type="text/javascript">
function pccs_change(v){
var pccs=new province_city_county_select();
var str="0";
for(i=0;i<v;i++){
str
+=("_"+(document.getElementById(pccs.s[i]).selectedIndex-1));
};
var ss=document.getElementById(pccs.s[v]);
with(ss){
length
=0;
options[
0]=new Option(pccs.defaultValue[v],pccs.defaultValue[v]);
if(v && document.getElementById(pccs.s[v-1]).selectedIndex>0||!v){
if(typeof(pccs.Items[str]) !="undefined"){
ar
= pccs.Items[str];
for(i=0;i<ar.length;i++){
options[length]
=new Option(ar[i],ar[i]);
}
if(v){
options[
0].selected =true;
}
}
}
if(++v<pccs.s.length){
pccs_change(v);
}
}
}

function province_city_county_select(){}

province_city_county_select.prototype
={
s:[
"s_province","s_city","s_county"],
defaultValue:[
"省份","地级市","市、县级市"],
Items:{},
add:
function(id,iArray){
this.Items[id] = iArray;
},
init:
function(){ //初始化函数
this.add("0",["北京市","天津市","上海市","重庆市","河北省","山西省","内蒙古","辽宁省","吉林省","黑龙江省","江苏省","浙江省","安徽省","福建省","江西省","山东省","河南省","湖北省","湖南省","广东省","广西","海南省","四川省","贵州省","云南省","西藏","陕西省","甘肃省","青海省","宁夏","新疆","香港","澳门","台湾省"]);
this.add("0_0_0",["东城区","西城区","崇文区","宣武区","朝阳区","丰台区","石景山区","海淀区","门头沟区","房山区","通州区","顺义区","昌平区","大兴区","怀柔区","平谷区","密云县","延庆县","延庆镇"]);
this.add("0_0",["北京市"]);
this.add("0_1_0",["和平区","河东区","河西区","南开区","河北区","红桥区","塘沽区","汉沽区","大港区","东丽区","西青区","津南区","北辰区","武清区","宝坻区","蓟县","宁河县","芦台镇","静海县","静海镇"]);
this.add("0_1",["天津市"]);
this.add("0_2_0",["黄浦区","卢湾区","徐汇区","长宁区","静安区","普陀区","闸北区","虹口区","杨浦区","闵行区","宝山区","嘉定区","浦东新区","金山区","松江区","青浦区","南汇区","奉贤区","崇明县","城桥镇"]);
this.add("0_2",["上海市"]);
this.add("0_3_0",["渝中区","大渡口区","江北区","沙坪坝区","九龙坡区","南岸区","北碚区","万盛区","双桥区","渝北区","巴南区","万州区","涪陵区","黔江区","长寿区","合川市","永川区市","江津市","南川市","綦江县","潼南县","铜梁县","大足县","荣昌县","璧山县","垫江县","武隆县","丰都县","城口县","梁平县","开县","巫溪县","巫山县","奉节县","云阳县","忠县","石柱土家族自治县","彭水苗族土家族自治县","酉阳土家族苗族自治县","秀山土家族苗族自治县"]);
this.add("0_3",["重庆市"]);

for(var j=0;j<this.s.length-1;j++){
document.getElementById(
this.s[j]).onchange=new Function("pccs_change("+(j+1)+")");
}
pccs_change(
0);
}
};

window.onload
=function(){
var pccs=new province_city_county_select();
pccs.init();
};
</script>
</head>
<body>
<select id="s_province"></select>
<select id="s_city"></select>
<select id="s_county"></select>
</body>
</html>

完整在线示例:http://jscode.chinacxy.com/code/676a2841c8701ac683a1b32144a62d07.aspx

artwl | 园豆:16736 (专家六级) | 2012-03-19 13:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册