Js做的城市三级联动,原创
原文出处:http://www.cnblogs.com/see7di/archive/2011/09/01/2239659.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>国家、省、市三级联动</title> 5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 6 <SCRIPT LANGUAGE="JavaScript"> 7 <!-- 8 function cn(){ 9 this.Items = {}; 10 } 11 cn.prototype.add = function(id,iArray){ 12 this.Items[id] = iArray; 13 } 14 cn.prototype.Exi = function(id){ 15 if(typeof(this.Items[id]) == "undefined"){return false;} 16 return true; 17 } 18 19 function chg(v){ 20 if(v==3){return;} 21 var str="0"; 22 for(i=0;i<v;i++){str+=("_"+(document.getElementById(s[i]).selectedIndex))}; 23 24 var ss=document.getElementById(s[v]); 25 with(ss){ 26 length = 0; //清理掉option 27 if(a_t.Exi(str)){ 28 ar=a_t.Items[str]; 29 for(i=0;i<ar.length;i++){ 30 options[length]=new Option(ar[i],ar[i]); 31 if(ar[i]==o[v]){options[i].selected=true;}//如果列表内包含初始项目则默认选中 32 } 33 } 34 if(++v<s.length){chg(v);} 35 } 36 } 37 38 39 var s=["tid1","tid2","tid3"]; 40 var o=["台湾","桃园","八德市"];//迎欢转载但请注明出处Email:See7di@Gmail.com,Seven的部落格http://hi.baidu.com/see7di/home 41 42 function setup(){ 43 for(i=1;i<=3;i++){ 44 document.getElementById(s[(i-1)]).onchange=new Function("chg("+(i)+")"); 45 } 46 chg(0); 47 } 48 49 var a_t = new cn(); 50 51 a_t.add("0",["中国","韩国","台湾"]); 52 53 a_t.add("0_0",["安徽","北京","福建","甘肃","广东","广西","贵州","海南","河北","河南","黑龙江","湖北","湖南","吉林","江苏","江西","辽宁","内蒙古","宁夏","青海","山东","山西"]); 54 a_t.add("0_0_0",["安庆","蚌埠","巢湖","池州","滁州","阜阳","合肥","淮北","淮南","黄山","六安","马鞍山","宿州","铜陵","芜湖","宣城","亳州"]); 55 a_t.add("0_0_1",["北京"]); 56 a_t.add("0_0_2",["福州","龙岩","南平","宁德","莆田","泉州","三明","厦门","漳州"]); 57 a_t.add("0_0_3",["白银","定西","甘南藏族自治州","嘉峪关","金昌","酒泉","兰州","临夏回族自治州","陇南","平凉","庆阳","天水","武威","张掖"]); 58 a_t.add("0_0_4",["潮州","东莞","佛山","广州","河源","深圳","阳江","云浮","湛江","肇庆","中山","珠海"]); 59 a_t.add("0_0_5",["百色","北海","崇左","防城港","桂林","贵港","河池","贺州","来宾","柳州","南宁","钦州","梧州","玉林"]); 60 a_t.add("0_0_6",["安顺","毕节","贵阳","六盘水","黔东南苗族侗族自治州","黔南布依族苗族自治州","黔西南布依族苗族自治州","铜仁","遵义"]); 61 a_t.add("0_0_7",["澄迈县","定安县","东方","海口",,"琼中黎族苗族自治县","三亚","屯昌县","万宁","文昌","五指山","儋州"]); 62 a_t.add("0_0_8",["保定","沧州","承德","邯郸","衡水","廊坊","秦皇岛","石家庄","唐山","邢台","张家口"]); 63 a_t.add("0_0_9",["安阳","鹤壁","济源","焦作","开封","洛阳","南阳","平顶山","三门峡","商丘","新乡","信阳","许昌","郑州","周口","驻马店","漯河","濮阳"]); 64 a_t.add("0_0_10",["大庆","大兴安岭","哈尔滨","鹤岗","黑河","鸡西","佳木斯","牡丹江","七台河","齐齐哈尔","双鸭山","绥化","伊春"]); 65 a_t.add("0_0_11",["鄂州","恩施土家族苗族自治州","黄冈","黄石","荆门","荆州","潜江","神农架林区","十堰","随州","天门","武汉","仙桃","咸宁","襄樊","孝感","宜昌"]); 66 a_t.add("0_0_12",["常德","长沙","郴州","衡阳","怀化","娄底","邵阳","湘潭","湘西土家族苗族自治州","益阳","永州","岳阳","张家界","株洲"]); 67 a_t.add("0_0_13",["白城","白山","长春","吉林","辽源","四平","松原","通化","延边朝鲜族自治州"]); 68 a_t.add("0_0_14",["常州","淮安","连云港","南京","南通","苏州","宿迁","泰州","无锡","徐州","盐城","扬州","镇江"]); 69 a_t.add("0_0_15",["抚州","赣州","吉安","景德镇","九江","南昌","萍乡","上饶","新余","宜春","鹰潭"]); 70 a_t.add("0_0_16",["鞍山","本溪","朝阳","大连","丹东","抚顺","阜新","葫芦岛","锦州","辽阳","盘锦","沈阳","铁岭","营口"]); 71 a_t.add("0_0_17",["阿拉善盟","巴彦淖尔盟","包头","赤峰","鄂尔多斯","呼和浩特","呼伦贝尔","通辽","乌海","乌兰察布盟","锡林郭勒盟","兴安盟"]); 72 a_t.add("0_0_18",["固原","石嘴山","吴忠","银川"]); 73 a_t.add("0_0_19",["果洛藏族自治州","海北藏族自治州","海东","海南藏族自治州","海西蒙古族藏族自治州","黄南藏族自治州","西宁","玉树藏族自治州"]); 74 a_t.add("0_0_20",["滨州","德州","东营","菏泽","济南","济宁","莱芜","聊城","临沂","青岛","日照","泰安","威海","潍坊","烟台","枣庄","淄博"]); 75 76 a_t.add("0_1",["汉城特別市","釜山广域市","大邱广域市","济州道"]); 77 a_t.add("0_1_0",["汉城"]); 78 a_t.add("0_1_1",["釜山","机张郡"]); 79 a_t.add("0_1_2",["大邱","达城郡"]); 80 a_t.add("0_1_3",["仁川","江华郡","瓮津郡"]); 81 a_t.add("0_1_4",["光州"]); 82 a_t.add("0_1_5",["大田"]); 83 a_t.add("0_1_6",["蔚山","蔚州郡"]); 84 a_t.add("0_1_7",["水原市","城南市","安山市","高阳市","安养市","富川市"]); 85 a_t.add("0_1_8",["春川市","原州市","江陵市"]); 86 a_t.add("0_1_9",["清州市"]); 87 a_t.add("0_1_10",["天安市"]); 88 a_t.add("0_1_11",["全州市","群山市","益山市"]); 89 a_t.add("0_1_12",["木浦市","丽水市","顺天市"]); 90 a_t.add("0_1_13",["浦项市","龟尾市","庆州市"]); 91 a_t.add("0_1_14",["昌原市","马山市","晋州市"]); 92 a_t.add("0_1_15",["济州市","西归浦市","北济州郡","南济州郡"]); 93 94 a_t.add("0_2",["基隆","台北","桃园","新竹","苗栗","台中","彰化","南投","云林","嘉义","台南","高雄","台东","花莲"]); 95 a_t.add("0_2_0",["基隆"]); 96 a_t.add("0_2_1",["台北"]); 97 a_t.add("0_2_2",["中壢市","平鎮市","龍潭鄉","楊梅鎮","新屋鄉","觀音鄉","龜山鄉","八德市","大溪鎮","復興鄉","大園鄉","蘆竹鄉"]); 98 a_t.add("0_2_3",["名古屋市 "]); 99 a_t.add("0_2_4",["札幌市"]); 100 a_t.add("0_2_5",["神戸市"]); 101 a_t.add("0_2_6",["京都市"]); 102 a_t.add("0_2_7",["福冈市"]); 103 a_t.add("0_2_8",["川崎市"]); 104 a_t.add("0_2_9",["埼玉市"]); 105 a_t.add("0_2_10",["广岛市"]); 106 a_t.add("0_2_11",["仙台市"]); 107 a_t.add("0_2_12",["北九州市 "]); 108 a_t.add("0_2_13",["千叶市"]); 109 110 //--> 111 </SCRIPT> 112 </head> 113 <body onLoad="setup()"> 114 <form method='post' action='@.php'> 115 <select id="tid1" name="tid1"></select> 116 <select id="tid2" name="tid2"></select> 117 <select id="tid3" name="tid3"></select> 118 119 <input type='submit' value='submit'> 120 </form>