js省市二级联动


//创建二维数组存储市级数据
city = new Object();
city[1]=new Array('北京市');
city[2]=new Array('天津市');
city[3]=new Array('石家庄','张家口','承德','秦皇岛','唐山','廊坊','保定','沧州','衡水','邢台','邯郸');
city[4]=new Array('太原','大同','朔州','阳泉','长治','晋城','忻州地区','吕梁地区','晋中','临汾地区','运城地区');
city[5]=new Array('呼和浩特','包头','乌海','赤市峰','通辽','鄂尔多斯','呼伦贝尔','巴彦淖尔','乌兰察布','兴安',"锡林郭勒","阿拉善");
city[6]=new Array('沈阳','大连','鞍山','抚顺','本溪','丹东','锦州','营口','阜新','辽阳','盘锦','铁岭','朝阳','葫芦岛');
city[7]=new Array('长春','吉林','四平','辽源','通化','白山','松原','白城','延边');
city[8]=new Array('哈尔滨','齐齐哈尔','鸡西','鹤岗','双鸭山','大庆','伊春','佳木斯','七台河','牡丹江','黑河','绥化','大兴安岭');
city[9]=new Array('上海');
city[10]=new Array('南京','无锡','徐州','常州','苏州','南通','连云港','淮安','盐城','扬州',' 镇江','泰州','宿迁');
city[11]=new Array('杭州','宁波','温州','嘉兴','湖州','绍兴','金华','衢州','舟山','台州','丽水');
city[12]=new Array('合肥','芜湖','蚌埠','淮南','马鞍山','淮北','铜陵','安庆','黄山','滁州','阜阳','宿州','巢湖','六安','亳州','池州','宣城');
city[13]=new Array('福州','厦门','莆田','三明','泉州','漳州','南平','龙岩','宁德');
city[14]=new Array('南昌','景德镇','萍乡','九江','新余','鹰潭','赣州','吉安','宜春','抚州','上饶');
city[15]=new Array('济南','青岛','淄博','枣庄','东营','烟台','潍坊','威海','济宁','泰安','日照','莱芜','临沂','德州','聊城' ,'滨州', '菏泽');
city[16]=new Array('郑州','开封','洛阳','平顶山','焦作','鹤壁','新乡','安阳','濮阳','许昌','漯河','三门峡','南阳','商丘','信阳','周口','驻马店');
city[17]=new Array( '武汉','黄石','襄樊','十堰','荆州','宜昌','荆门','鄂州','孝感','黄冈','咸宁','随州','恩施');
city[18]=new Array('长沙','株洲','湘潭','衡阳','邵阳','岳阳','常德','张家界','益阳','郴州','永州','怀化','娄底','湘西');
city[19]=new Array('广州','深圳','珠海','汕头','韶关','佛山','江门','湛江','茂名','肇庆','惠州','梅州','汕尾','河源','阳江','清远','东莞','中山','潮州','揭阳','云浮');
city[20]=new Array('南宁','柳州','桂林','梧州','北海','防城港','钦州','贵港','玉林','百色','贺州','河池','来宾','崇左');
city[21]=new Array('海口','三亚');
city[22]=new Array('重庆市');
city[23]=new Array('成都','自贡','攀枝花','泸州','德阳','绵阳','广元','遂宁','内江','乐山','南充','宜宾','广安','达州','眉山','雅安','巴中','资阳','阿坝','凉山');
city[24]=new Array( '贵阳','六盘水','遵义','安顺','铜仁','毕节','黔西南','黔东南','黔南');
city[25]=new Array('昆明','曲靖','玉溪','保山','昭通','丽江','普洱','临沧','文山','红河','西双版纳','楚雄','大理','德宏','怒江','迪庆');
city[26]=new Array('拉萨','昌都','山南','那曲','阿里','林芝');
city[27]=new Array('西安','铜川','宝鸡','咸阳','渭南','延安','汉中','榆林','安康','商洛');
city[28]=new Array('兰州','嘉峪关','金昌','白银','天水','武威','张掖','平凉','酒泉','庆阳','定西','陇南','临夏','甘南');
city[29]=new Array('西宁','海东','海北','黄南','海南','果洛','玉树','海西');
city[30]=new Array('银川','石嘴山','吴忠','固原','中卫');
city[31]=new Array('乌鲁木齐','克拉玛依','吐鲁番' ,'哈密','和田','阿克苏','喀什','克孜勒苏柯尔克孜','巴音郭楞蒙古','昌吉','博尔塔拉蒙古','伊犁哈萨克','塔城','阿勒泰');


function cityFunction(){
    var obj=$("#provinceId")[0];        //获取省级选中的值   provinceId省级Id
    var len = obj.length;
    for(var i = 0;i请选择");             //citiesId市级下拉列表的Id       
                    var len1 = vl.length;
                    for(var i = 0;i" + vl[i] + "");
                    }
                    break;
             }
        }
    }
}

 

附上所实现的html代码


注:省级中的value要和数组中的下表要一致才能随着选中的省级联动出对应的市级

有错的地方麻烦留言纠正

你可能感兴趣的:(jquery,js)