JavaScript打造省市两级联动无刷新下拉
来源:程序员人生 发布时间:2014-01-06 10:29:41 阅读次数:3835次
前段时间帮一个朋友修改一个项目,严格地讲应该是烂尾工程,里面用到省市两级联动,居然用到AJAX,也就是说每改变一个省,都不得不从数据库中去遍历一次相关的市,而且整个过程没有缓存,也没用到任何AJAX框架,导致客户体验相当的差,因为会慢半拍,或者报错!~.既然是朋友,那我决定帮他稍稍改进一下这个错误.以增强客户体验.
JS源码是这样的:
CityCodeList.js:
var cityArr = new Array(340);
cityArr[0] = new Array('110100','北京','010','beijing','110000');
cityArr[1] = new Array('130100','石家庄','0311','shijiazhuang','130000');
cityArr[2] = new Array('130200','唐山','0315','tangshan','130000');
cityArr[3] = new Array('130300','秦皇岛','0335','qinhuangdao','130000');
cityArr[4] = new Array('130400','邯郸','0310','handan','130000');
cityArr[5] = new Array('130500','邢台','0319','xingtai','130000');
cityArr[6] = new Array('130600','保定','0312','baoding','130000');
cityArr[7] = new Array('130700','张家口','0313','zhangjiakou','130000');
cityArr[8] = new Array('130800','承德','0314','chengde','130000');
cityArr[9] = new Array('130900','沧州','0317','cangzhou','130000');
cityArr[10] = new Array('131000','廊坊','0316','langfang','130000');
cityArr[11] = new Array('131100','衡水','0318','hengshui','130000');
cityArr[12] = new Array('140100','太原','0351','taiyuan','140000');
cityArr[13] = new Array('140200','大同','0352','datong','140000');
cityArr[14] = new Array('140300','阳泉','3053','yangquan','140000');
cityArr[15] = new Array('140400','长治','0355','changzhi','140000');
cityArr[16] = new Array('140500','晋城','0356','jincheng','140000');
cityArr[17] = new Array('140600','朔州','0394','szhou','140000');
cityArr[18] = new Array('140700','晋中','0354','jinzhong','140000');
cityArr[19] = new Array('140800','运城','0359','yuncheng','140000');
cityArr[20] = new Array('140900','忻州','0350','yizhou','140000');
cityArr[21] = new Array('141000','临汾','0357','linfen','140000');
cityArr[22] = new Array('141100','吕梁','0358','lvliang','140000');
cityArr[23] = new Array('150100','呼和浩特','0471','huhehaote','150000');
cityArr[24] = new Array('150200','包头','0472','baotou','150000');
cityArr[25] = new Array('150300','乌海','0473','wuhai','150000');
cityArr[26] = new Array('150400','赤峰','0476','chifeng','150000');
cityArr[27] = new Array('150500','通辽','0475','tongliao','150000');
cityArr[28] = new Array('150600','鄂尔多斯','0477','erduosi','150000');
cityArr[29] = new Array('150700','呼伦贝尔','0470','hulunbeier','150000');
cityArr[30] = new Array('150800','巴彦淖尔','0478','bayanzhuoer','150000');
cityArr[31] = new Array('150900','乌兰察布','0474','wulanchabu','150000');
cityArr[32] = new Array('152200','兴安盟','0482','xinganmeng','150000');
cityArr[33] = new Array('152500','锡林郭勒盟','0479','xilinguolemeng','150000');
cityArr[34] = new Array('152900','阿拉善盟','0483','alashanmeng','150000');
cityArr[35] = new Array('210100','沈阳','024','shenyang','210000');
cityArr[36] = new Array('210200','大连','0411','dalian','210000');
cityArr[37] = new Array('210300','鞍山','0412','anshan','210000');
cityArr[38] = new Array('210400','抚顺','0413','fushun','210000');
cityArr[39] = new Array('210500','本溪','0414','benxi','210000');
cityArr[40] = new Array('210600','丹东','0415','dandong','210000');
cityArr[41] = new Array('210700','锦州','0416','jinzhou','210000');
cityArr[42] = new Array('210800','营口','0417','yingkou','210000');
cityArr[43] = new Array('210900','阜新','0418','fuxin','210000');
cityArr[44] = new Array('211000','辽阳','0419','liaoyang','210000');
cityArr[45] = new Array('211100','盘锦','0427','panjin','210000');
cityArr[46] = new Array('211200','铁岭','0410','tieling','210000');
cityArr[47] = new Array('211300','朝阳','0421','chaoyang','210000');
cityArr[48] = new Array('211400','葫芦岛','0429','huludao','210000');
cityArr[49] = new Array('220100','长春','0431','changchun','220000');
cityArr[50] = new Array('220200','吉林','0432','jilin','220000');
cityArr[51] = new Array('220300','四平','0434','siping','220000');
cityArr[52] = new Array('220400','辽源','0437','liaoyuan','220000');
cityArr[53] = new Array('220500','通化','0435','tonghua','220000');
cityArr[54] = new Array('220600','白山','0439','baishan','220000');
cityArr[55] = new Array('220700','松原','0438','songyuan','220000');
cityArr[56] = new Array('220800','白城','0436','baicheng','220000');
cityArr[57] = new Array('222400','延边','0433','yanbian','220000');
cityArr[58] = new Array('230100','哈尔滨','0451','haerbin','230000');
cityArr[59] = new Array('230200','齐齐哈尔','0452','qiqihaer','230000');
cityArr[60] = new Array('230300','鸡西','0467','jixi','230000');
cityArr[61] = new Array('230400','鹤岗','0468','hegang','230000');
cityArr[62] = new Array('230500','双鸭山','0469','shuangyashan','230000');
cityArr[63] = new Array('230600','大庆','0459','daqing','230000');
cityArr[64] = new Array('230700','伊春','0458','yichun','230000');
cityArr[65] = new Array('230800','佳木斯','0454','jiamusi','230000');
cityArr[66] = new Array('230900','七台河','0464','qitaihe','230000');
cityArr[67] = new Array('231000','牡丹江','0453','mudanjiang','230000');
cityArr[68] = new Array('231100','黑河','0456','heihe','230000');
cityArr[69] = new Array('231200','绥化','0455','suihua','230000');
cityArr[70] = new Array('232700','大兴安岭','0457','daxinganling','230000');
cityArr[71] = new Array('310100','上海','021','shanghai','310000');
cityArr[72] = new Array('320100','南京','025','nanjing','320000');
cityArr[73] = new Array('320200','无锡','0510','wuxi','320000');
cityArr[74] = new Array('320300','徐州','0516','xuzhou','320000');
cityArr[75] = new Array('320400','常州','0519','changzhou','320000');
cityArr[76] = new Array('320500','苏州','0512','suzhou','320000');
cityArr[77] = new Array('320600','南通','0513','nantong','320000');
cityArr[78] = new Array('320700','连云港','0518','lianyungang','320000');
cityArr[79] = new Array('320800','淮安','0517','huaian','320000');
cityArr[80] = new Array('320900','盐城','0515','yancheng','320000');
cityArr[81] = new Array('321000','扬州','0514','yangzhou','320000');
cityArr[82] = new Array('321100','镇江','0511','zhenjiang','320000');
cityArr[83] = new Array('321200','泰州','0523','taizhou','320000');
cityArr[84] = new Array('321300','宿迁','0527','suqian','320000');
cityArr[85] = new Array('330100','杭州','0571','hangzhou','330000');
cityArr[86] = new Array('330200','宁波','0574','ningbo','330000');
cityArr[87] = new Array('330300','温州','0577','wenzhou','330000');
cityArr[88] = new Array('330400','嘉兴','0573','jiaxing','330000');
cityArr[89] = new Array('330500','湖州','0572','huzhou','330000');
cityArr[90] = new Array('330600','绍兴','0575','shaoxing','330000');
cityArr[91] = new Array('330700','金华','0579','jinhua','330000');
cityArr[92] = new Array('330800','衢州','0570','quzhou','330000');
cityArr[93] = new Array('330900','舟山','0580','zhoushan','330000');
cityArr[94] = new Array('331000','台州','0576','tzhou','330000');
cityArr[95] = new Array('331100','丽水','0578','lishui','330000');
cityArr[96] = new Array('340100','合肥','0551','hefei','340000');
cityArr[97] = new Array('340200','芜湖','0553','wuhu','340000');
cityArr[98] = new Array('340300','蚌埠','0552','bengbu','340000');
cityArr[99] = new Array('340400','淮南','0554','huainan','340000');
cityArr[100] = new Array('340500','马鞍山','0555','maanshan','340000');
cityArr[101] = new Array('340600','淮北','0561','huaibei','340000');
cityArr[102] = new Array('340700','铜陵','0562','tongling','340000');
cityArr[103] = new Array('340800','安庆','0556','anqing','340000');
cityArr[104] = new Array('341000','黄山','0559','huangshan','340000');
cityArr[105] = new Array('341100','滁州','0550','chuzhou','340000');
cityArr[106] = new Array('341200','阜阳','0558','fuyang','340000');
cityArr[107] = new Array('341300','宿州','0557','suzh','340000');
cityArr[108] = new Array('341400','巢湖','0565','chaohu','340000');
cityArr[109] = new Array('341500','六安','0564','liuan','340000');
cityArr[110] = new Array('341600','亳州','0558','bozhou','340000');
cityArr[111] = new Array('341700','池州','0566','chizhou','340000');
cityArr[112] = new Array('341800','宣城','0563','xuancheng','340000');
cityArr[113] = new Array('350100','福州','0591','fzhou','350000');
cityArr[114] = new Array('350200','厦门','0592','xiamen','350000');
cityArr[115] = new Array('350300','莆田','0594','putian','350000');
cityArr[116] = new Array('350400','三明','0598','sanming','350000');
cityArr[117] = new Array('350500','泉州','0595','quanzhou','350000');
cityArr[118] = new Array('350600','漳州','0596','zhangzhou','350000');
cityArr[119] = new Array('350700','南平','0599','nanping','350000');
cityArr[120] = new Array('350800','龙岩','0597','longyan','350000');
cityArr[121] = new Array('350900','宁德','0593','ningde','350000');
cityArr[122] = new Array('360100','南昌','0791','nanchang','360000');
cityArr[123] = new Array('360200','景德镇','0798','jingdezhen','360000');
cityArr[124] = new Array('360300','萍乡','0799','pingxiang','360000');
cityArr[125] = new Array('360400','九江','0792','jiujiang','360000');
cityArr[126] = new Array('360500','新余','0790','xinyu','360000');
cityArr[127] = new Array('360600','鹰潭','0701','yingtan','360000');
cityArr[128] = new Array('360700','赣州','0797','ganzhou','360000');
cityArr[129] = new Array('360800','吉安','0796','jian','360000');
cityArr[130] = new Array('360900','宜春','0795','ychun','360000');
cityArr[131] = new Array('361000','抚州','0794','fuzhou','360000');
cityArr[132] = new Array('361100','上饶','0793','shangrao','360000');
cityArr[133] = new Array('370100','济南','0531','jinan','370000');
cityArr[134] = new Array('370200','青岛','0532','qingdao','370000');
cityArr[135] = new Array('370300','淄博','0533','zibo','370000');
cityArr[136] = new Array('370400','枣庄','0632','zaozhuang','370000');
cityArr[137] = new Array('370500','东营','0546','dongying','370000');
cityArr[138] = new Array('370600','烟台','0535','yantai','370000');
cityArr[139] = new Array('370700','潍坊','0536','weifang','370000');
cityArr[140] = new Array('370800','济宁','0537','jining','370000');
cityArr[141] = new Array('370900','泰安','0538','taian','370000');
cityArr[142] = new Array('371000','威海','0631','weihai','370000');
cityArr[143] = new Array('371100','日照','0633','rizhao','370000');
cityArr[144] = new Array('371200','莱芜','0634','laiwu','370000');
cityArr[145] = new Array('371300','临沂','0539','linyi','370000');
cityArr[146] = new Array('371400','德州','0715','dezhou','370000');
cityArr[147] = new Array('371500','聊城','0635','liaocheng','370000');
cityArr[148] = new Array('371600','滨州','0543','binzhou','370000');
cityArr[149] = new Array('371700','菏泽','0530','heze','370000');
cityArr[150] = new Array('410100','郑州','0371','zhengzhou','410000');
cityArr[151] = new Array('410200','开封','0378','kaifeng','410000');
cityArr[152] = new Array('410300','洛阳','0379','luoyang','410000');
cityArr[153] = new Array('410400','平顶山','0375','pingdingshan','410000');
cityArr[154] = new Array('410500','安阳','0372','anyang','410000');
cityArr[155] = new Array('410600','鹤壁','0392','hebi','410000');
cityArr[156] = new Array('410700','新乡','0373','xinxiang','410000');
cityArr[157] = new Array('410800','焦作','0391','jiaozuo','410000');
cityArr[158] = new Array('410900','濮阳','0393','puyang','410000');
cityArr[159] = new Array('411000','许昌','0374','xuchang','410000');
cityArr[160] = new Array('411100','漯河','0395','luohe','410000');
cityArr[161] = new Array('411200','三门峡','0398','sanmenxia','410000');
cityArr[162] = new Array('411300','南阳','0377','nanyang','410000');
cityArr[163] = new Array('411400','商丘','0370','shangqiu','410000');
cityArr[164] = new Array('411500','信阳','0370','xinyang','410000');
cityArr[165] = new Array('411600','周口','0394','zhoukou','410000');
cityArr[166] = new Array('411700','驻马店','0396','zhumadian','410000');
cityArr[167] = new Array('420100','武汉','027','wuhan','420000');
cityArr[168] = new Array('420200','黄石','0714','huangshi','420000');
cityArr[169] = new Array('420300','十堰','0719','shiyan','420000');
cityArr[170] = new Array('420500','宜昌','0717','yichang','420000');
cityArr[171] = new Array('420600','襄樊','0710','xiangfan','420000');
cityArr[172] = new Array('420700','鄂州','0711','ezhou','420000');
cityArr[173] = new Array('420800','荆门','0724','jingmen','420000');
cityArr[174] = new Array('420900','孝感','0712','xiaogan','420000');
cityArr[175] = new Array('421000','荆州','0716','jingzhou','420000');
cityArr[176] = new Array('421100','黄冈','0713','huanggang','420000');
cityArr[177] = new Array('421200','咸宁','0715','xianning','420000');
cityArr[178] = new Array('421300','随州','0722','suizhou','420000');
cityArr[179] = new Array('422800','恩施','0718','enshi','420000');
cityArr[180] = new Array('429000','湖北','027','hubei','420000');
cityArr[181] = new Array('430100','长沙','0731','changsha','430000');
cityArr[182] = new Array('430200','株洲','0733','zhuzhou','430000');
cityArr[183] = new Array('430300','湘潭','0732','xiangtan','430000');
cityArr[184] = new Array('430400','衡阳','0734','hengyang','430000');
cityArr[185] = new Array('430500','邵阳','0739','shaoyang','430000');
cityArr[186] = new Array('430600','岳阳','0730','yueyang','430000');
cityArr[187] = new Array('430700','常德','0736','changde','430000');
cityArr[188] = new Array('430800','张家界','0744','zhangjiajie','430000');
cityArr[189] = new Array('430900','益阳','0737','yiyang','430000');
cityArr[190] = new Array('431000','郴州','0735','chenzhou','430000');
cityArr[191] = new Array('431100','永州','0746','yongzhou','430000');
cityArr[192] = new Array('431200','怀化','0745','huaihua','430000');
cityArr[193] = new Array('431300','娄底','0738','loudi','430000');
cityArr[194] = new Array('433100','湘西','0743','xiangxi','430000');
cityArr[195] = new Array('440100','广州','020','guangzhou','440000');
cityArr[196] = new Array('440200','韶关','0751','shaoguan','440000');
cityArr[197] = new Array('440300','深圳','0755','shenzhen','440000');
cityArr[198] = new Array('440400','珠海','0756','zhuhai','440000');
cityArr[199] = new Array('440500','汕头','0754','shantou','440000');
cityArr[200] = new Array('440600','佛山','0757','foshan','440000');
cityArr[201] = new Array('440700','江门','0750','jiangmen','440000');
cityArr[202] = new Array('440800','湛江','0759','zhanjiang','440000');
cityArr[203] = new Array('440900','茂名','0668','maoming','440000');
cityArr[204] = new Array('441200','肇庆','0758','zhaoqing','440000');
cityArr[205] = new Array('441300','惠州','0752','huizhou','440000');
cityArr[206] = new Array('441400','梅州','0753','meizhou','440000');
cityArr[207] = new Array('441500','汕尾','0660','shanwei','440000');
cityArr[208] = new Array('441600','河源','0762','heyuan','440000');
cityArr[209] = new Array('441700','阳江','0662','yangjiang','440000');
cityArr[210] = new Array('441800','清远','0763','qingyuan','440000');
cityArr[211] = new Array('441900','东莞','0769','dongguan','440000');
cityArr[212] = new Array('442000','中山','0760','zhongshan','440000');
cityArr[213] = new Array('445100','潮州','0768','chaozhou','440000');
cityArr[214] = new Array('445200','揭阳','0663','jieyang','440000');
cityArr[215] = new Array('445300','云浮','0766','yunfu','440000');
cityArr[216] = new Array('450100','南宁','0771','nanning','450000');
cityArr[217] = new Array('450200','柳州','0772','liuzhou','450000');
cityArr[218] = new Array('450300','桂林','0773','guilin','450000');
cityArr[219] = new Array('450400','梧州','0774','wuzhou','450000');
cityArr[220] = new Array('450500','北海','0779','beihai','450000');
cityArr[221] = new Array('450600','防城港','0770','fangchenggang','450000');
cityArr[222] = new Array('450700','钦州','0777','qinzhou','450000');
cityArr[223] = new Array('450800','贵港','0775','guigang','450000');
cityArr[224] = new Array('450900','玉林','0775','ylin','450000');
cityArr[225] = new Array('451000','百色','0776','baise','450000');
cityArr[226] = new Array('451100','贺州','0774','hezhou','450000');
cityArr[227] = new Array('451200','河池','0778','hechi','450000');
cityArr[228] = new Array('451300','来宾','0772','laibin','450000');
cityArr[229] = new Array('451400','崇左','0771','chongzuo','450000');
cityArr[230] = new Array('460100','海口','0898','haikou','460000');
cityArr[231] = new Array('460200','三亚','0899','sanya','460000');
cityArr[232] = new Array('469000','海南','0890','hainan','460000');
cityArr[233] = new Array('500100','重庆','023','chongqing','500000');
cityArr[234] = new Array('510100','成都','028','chengdu','510000');
cityArr[235] = new Array('510300','自贡','0813','zigong','510000');
cityArr[236] = new Array('510400','攀枝花','0812','panzhihua','510000');
cityArr[237] = new Array('510500','泸州','0830','luzhou','510000');
cityArr[238] = new Array('510600','德阳','0838','deyang','510000');
cityArr[239] = new Array('510700','绵阳','0816','mianyang','510000');
cityArr[240] = new Array('510800','广元','0839','guangyuan','510000');
cityArr[241] = new Array('510900','遂宁','0825','suining','510000');
cityArr[242] = new Array('511000','内江','0832','neijiang','510000');
cityArr[243] = new Array('511100','乐山','0833','leshan','510000');
cityArr[244] = new Array('511300','南充','0817','nanchong','510000');
cityArr[245] = new Array('511400','眉山','0833','meishan','510000');
cityArr[246] = new Array('511500','宜宾','0831','yibin','510000');
cityArr[247] = new Array('511600','广安','0826','guangan','510000');
cityArr[248] = new Array('511700','达州','0818','dazhou','510000');
cityArr[249] = new Array('511800','雅安','0835','yaan','510000');
cityArr[250] = new Array('511900','巴中','0827','bazhong','510000');
cityArr[251] = new Array('512000','资阳','0832','ziyang','510000');
cityArr[252] = new Array('513200','阿坝','0837','aba','510000');
cityArr[253] = new Array('513300','甘孜','0836','ganzi','510000');
cityArr[254] = new Array('513400','凉山','0834','liangshan','510000');
cityArr[255] = new Array('520100','贵阳','0851','guiyang','520000');
cityArr[256] = new Array('520200','六盘水','0858','liupanshui','520000');
cityArr[257] = new Array('520300','遵义','0852','zunyi','520000');
cityArr[258] = new Array('520400','安顺','0853','anshun','520000');
cityArr[259] = new Array('522200','铜仁','0856','tongren','520000');
cityArr[260] = new Array('522300','黔西南','0859','qianxinan','520000');
cityArr[261] = new Array('522400','毕节','0857','bijie','520000');
cityArr[262] = new Array('522600','黔东南','0855','qiandongnan','520000');
cityArr[263] = new Array('522700','黔南','0854','qiannan','520000');
cityArr[264] = new Array('530100','昆明','0871','kunming','530000');
cityArr[265] = new Array('530300','曲靖','0874','qujing','530000');
cityArr[266] = new Array('530400','玉溪','0877','yuxi','530000');
cityArr[267] = new Array('530500','保山','0875','baoshan','530000');
cityArr[268] = new Array('530600','昭通','0870','zhaotong','530000');
cityArr[269] = new Array('530700','丽江','0888','lijiang','530000');
cityArr[270] = new Array('530800','思茅','0879','simao','530000');
cityArr[271] = new Array('530900','临沧','0883','lincang','530000');
cityArr[272] = new Array('532300','楚雄','0878','chuxiong','530000');
cityArr[273] = new Array('532500','红河','0873','honghe','530000');
cityArr[274] = new Array('532600','文山','0876','wenshan','530000');
cityArr[275] = new Array('532800','西双版纳','0691','xishuangbanna','530000');
cityArr[276] = new Array('532900','大理','0872','dali','530000');
cityArr[277] = new Array('533100','德宏','0692','dehong','530000');
cityArr[278] = new Array('533300','怒江','0886','nujiang','530000');
cityArr[279] = new Array('533400','迪庆','0887','diqing','530000');
cityArr[280] = new Array('540100','拉萨','0891','lasa','540000');
cityArr[281] = new Array('542100','昌都','0895','changdu','540000');
cityArr[282] = new Array('542200','山南','0893','shannan','540000');
cityArr[283] = new Array('542300','日喀则','0892','rigaze','540000');
cityArr[284] = new Array('542400','那曲','0896','naqu','540000');
cityArr[285] = new Array('542500','阿里','0897','ali','540000');
cityArr[286] = new Array('542600','林芝','0894','linzhi','540000');
cityArr[287] = new Array('610100','西安','029','xian','610000');
cityArr[288] = new Array('610200','铜川','0919','tongchuan','610000');
cityArr[289] = new Array('610300','宝鸡','0917','baoji','610000');
cityArr[290] = new Array('610400','咸阳','0910','xianyang','610000');
cityArr[291] = new Array('610500','渭南','0913','weinan','610000');
cityArr[292] = new Array('610600','延安','0911','yanan','610000');
cityArr[293] = new Array('610700','汉中','0916','hanzhong','610000');
cityArr[294] = new Array('610800','榆林','0912','yulin','610000');
cityArr[295] = new Array('610900','安康','0915','ankang','610000');
cityArr[296] = new Array('611000','商洛','0914','shangluo','610000');
cityArr[297] = new Array('620100','兰州','0931','lanzhou','620000');
cityArr[298] = new Array('620200','嘉峪关','0937','jiayuguan','620000');
cityArr[299] = new Array('620300','金昌','0935','jinchang','620000');
cityArr[300] = new Array('620400','白银','0943','baiyin','620000');
cityArr[301] = new Array('620500','天水','0938','tianshui','620000');
cityArr[302] = new Array('620600','武威','0935','wuwei','620000');
cityArr[303] = new Array('620700','张掖','0936','zhangye','620000');
cityArr[304] = new Array('620800','平凉','0933','pingliang','620000');
cityArr[305] = new Array('620900','酒泉','0937','jiuquan','620000');
cityArr[306] = new Array('621000','庆阳','0934','qingyang','620000');
cityArr[307] = new Array('621100','定西','0932','dingxi','620000');
cityArr[308] = new Array('621200','陇南','0939','longnan','620000');
cityArr[309] = new Array('622900','临夏','0930','linxia','620000');
cityArr[310] = new Array('623000','甘南','0941','gannan','620000');
cityArr[311] = new Array('630100','西宁','0971','xining','630000');
cityArr[312] = new Array('632100','海东','0972','haidong','630000');
cityArr[313] = new Array('632200','海北州','0970','haibeizhou','630000');
cityArr[314] = new Array('632300','黄南州','0973','huangnanzhou','630000');
cityArr[315] = new Array('632500','海南州','0974','hainanzhou','630000');
cityArr[316] = new Array('632600','果洛州','0975','guoluozhou','630000');
cityArr[317] = new Array('632700','玉树州','0976','yushuzhou','630000');
cityArr[318] = new Array('632800','海西州','0979','haixizhou','630000');
cityArr[319] = new Array('640100','银川','0976','yinchuan','640000');
cityArr[320] = new Array('640200','石嘴山','0952','shizuishan','640000');
cityArr[321] = new Array('640300','吴忠','0953','wuzhong','640000');
cityArr[322] = new Array('640400','固原','0954','guyuan','640000');
cityArr[323] = new Array('640500','中卫','0955','zhongwei','640000');
cityArr[324] = new Array('650100','乌鲁木齐','0991','wulumuqi','650000');
cityArr[325] = new Array('650200','克拉玛依','0990','kelamayi','650000');
cityArr[326] = new Array('652100','吐鲁番','0995','tulufan','650000');
cityArr[327] = new Array('652200','哈密','0902','hami','650000');
cityArr[328] = new Array('652300','昌吉州','0994','changjizhou','650000');
cityArr[329] = new Array('652700','博尔塔拉州','0909','boertalazhou','650000');
cityArr[330] = new Array('652800','巴音郭楞蒙古','0996','bayinguoleng','650000');
cityArr[331] = new Array('652900','阿克苏','0997','akesu','650000');
cityArr[332] = new Array('653000','克孜勒苏柯尔克孜','0908','kezilesukeerkezi','650000');
cityArr[333] = new Array('653100','喀什','0998','geshi','650000');
cityArr[334] = new Array('653200','和田','0903','hetian','650000');
cityArr[335] = new Array('654000','伊犁哈萨克','0999','yilihasa','650000');
cityArr[336] = new Array('654200','塔城','0901','tacheng','650000');
cityArr[337] = new Array('654300','阿勒泰','0906','aletai','650000');
cityArr[338] = new Array('659000','新--疆','0900','xinjiang','650000');
cityArr[339] = new Array('120100','天津','022','tianjin','120000');
function getCityCodeByAll(str){//根据城市代码,城市名,区号,拼音得到城市代码
return getCityItemFromArr(0,str);
}
function getCityNameByAll(str){//根据城市代码,城市名,区号,拼音得到城市名称
return getCityItemFromArr(1,str);
}
function getAreaCodeByAll(str){//根据城市代码,城市名,区号,拼音得到城市区号
return getCityItemFromArr(2,str);
}
function getPinyinByAll(str){//根据城市代码,城市名,区号,拼音得到城市拼音
return getCityItemFromArr(3,str);
}
function getProvinceCodeByAll(str){//根据城市代码,城市名,区号,拼音得到其所属省的代码
return getCityItemFromArr(4,str);
}
function getCitysByProvinceCode(str){//根据省代码,得到一个城市的相关数据(联动可用)
var citysArr = new Array();
for(var i=0;i<cityArr.length;i++){
if(cityArr[i][4] == str){
citysArr.push(new Array(cityArr[i][0],cityArr[i][1],cityArr[i][2],cityArr[i][3]));
}
}
return citysArr;
}
function getCityItemFromArr(resultIndex,searchStr){//0:cityCode,1:cityName,2:areacode,3:pinyin;4:provinceCode
if(searchStr != ''){
for(var i=0;i<cityArr.length;i++){
for(var j=0;j<5;j++){
if(cityArr[i][j] == searchStr){
return cityArr[i][resultIndex];
}
}
}
}
return 0;
}
function changsheng(va,cityControlName)
{
if(va!='0')
{
var f=document.getElementById(cityControlName);
var citysArr = getCitysByProvinceCode(va);
if(f.options.length > 1){//clear olditems
for(var i=f.options.length-1;i>0;i--){
f.options.remove(i);
}
}
for(var i=0;i<citysArr.length;i++){
f.add(new Option(citysArr[i][1],citysArr[i][0]));
}
}
}
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠