`
liufei.fir
  • 浏览: 685021 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

jquery 中国省市信息联动插件

阅读更多
/***
 * 插件名称: 中国省市信息联动插件
 */

$._cityInfo = [{"n":"北京市","c":["北京市"]},
{"n":"天津市","c":["天津市"]},
{"n":"上海市","c":["上海市"]},
{"n":"重庆市","c":["重庆市"]},
{"n":"河北省","c":["石家庄市","唐山市","秦皇岛市","邯郸市","邢台市","保定市","张家口市","承德市","沧州市","廊坊市","衡水市"]},
{"n":"山西省","c":["太原市","大同市","阳泉市","长治市","晋城市","朔州市","晋中市","运城市","忻州市","临汾市","吕梁市"]},
{"n":"台湾省","c":["台北市","高雄市","基隆市","台中市","台南市","新竹市","嘉义市","台北县","宜兰县","桃园县","新竹县","苗栗县","台中县","彰化县","南投县","云林县","嘉义县","台南县","高雄县","屏东县","澎湖县","台东县","花莲县"]},
{"n":"辽宁省","c":["沈阳市","大连市","鞍山市","抚顺市","本溪市","丹东市","锦州市","营口市","阜新市","辽阳市","盘锦市","铁岭市","朝阳市","葫芦岛市"]},
{"n":"吉林省","c":["长春市","吉林市","四平市","辽源市","通化市","白山市","松原市","白城市","延边朝鲜族自治州"]},
{"n":"黑龙江省","c":["哈尔滨市","齐齐哈尔市","鹤岗市","双鸭山市","鸡西市","大庆市","伊春市","牡丹江市","佳木斯市","七台河市","黑河市","绥化市","大兴安岭地区"]},
{"n":"江苏省","c":["南京市","无锡市","徐州市","常州市","苏州市","南通市","连云港市","淮安市","盐城市","扬州市","镇江市","泰州市","宿迁市"]},
{"n":"浙江省","c":["杭州市","宁波市","温州市","嘉兴市","湖州市","绍兴市","金华市","衢州市","舟山市","台州市","丽水市"]},
{"n":"安徽省","c":["合肥市","芜湖市","蚌埠市","淮南市","马鞍山市","淮北市","铜陵市","安庆市","黄山市","滁州市","阜阳市","宿州市","巢湖市","六安市","亳州市","池州市","宣城市"]},
{"n":"福建省","c":["福州市","厦门市","莆田市","三明市","泉州市","漳州市","南平市","龙岩市","宁德市"]},
{"n":"江西省","c":["南昌市","景德镇市","萍乡市","九江市","新余市","鹰潭市","赣州市","吉安市","宜春市","抚州市","上饶市"]},
{"n":"山东省","c":["济南市","青岛市","淄博市","枣庄市","东营市","烟台市","潍坊市","济宁市","泰安市","威海市","日照市","莱芜市","临沂市","德州市","聊城市","滨州市","荷泽市"]},
{"n":"河南省","c":["郑州市","开封市","洛阳市","平顶山市","安阳市","鹤壁市","新乡市","焦作市","濮阳市","许昌市","漯河市","三门峡市","南阳市","商丘市","信阳市","周口市","驻马店市"]},
{"n":"湖北省","c":["武汉市","黄石市","十堰市","宜昌市","襄樊市","鄂州市","荆门市","孝感市","荆州市","黄冈市","咸宁市","随州市","恩施土家族苗族自治州","仙桃市","潜江市","天门市","神农架林区"]},
{"n":"湖南省","c":["长沙市","株洲市","湘潭市","衡阳市","邵阳市","岳阳市","常德市","张家界市","益阳市","郴州市","永州市","怀化市","娄底市","湘西土家族苗族自治州"]},
{"n":"广东省","c":["广州市","深圳市","珠海市","汕头市","韶关市","佛山市","江门市","湛江市","茂名市","肇庆市","惠州市","梅州市","汕尾市","河源市","阳江市","清远市","东莞市","中山市","潮州市","揭阳市","云浮市"]},
{"n":"甘肃省","c":["兰州市","金昌市","白银市","天水市","嘉峪关市","武威市","张掖市","平凉市","酒泉市","庆阳市","定西市","陇南市","临夏回族自治州","甘南藏族自治州"]},
{"n":"四川省","c":["成都市","自贡市","攀枝花市","泸州市","德阳市","绵阳市","广元市","遂宁市","内江市","乐山市","南充市","眉山市","宜宾市","广安市","达州市","雅安市","巴中市","资阳市","阿坝藏族羌族自治州","甘孜藏族自治州","凉山彝族自治州"]},
{"n":"贵州省","c":["贵阳市","六盘水市","遵义市","安顺市","铜仁地区","毕节地区","黔西南布依族苗族自治州","黔东南苗族侗族自治州","黔南布依族苗族自治州"]},
{"n":"海南省","c":["海口市","三亚市","五指山市","琼海市","儋州市","文昌市","万宁市","东方市","澄迈县","定安县","屯昌县","临高县","白沙黎族自治县","昌江黎族自治县","乐东黎族自治县","陵水黎族自治县","保亭黎族苗族自治县","琼中黎族苗族自治县"]},
{"n":"云南省","c":["昆明市","曲靖市","玉溪市","保山市","昭通市","丽江市","思茅市","临沧市","楚雄彝族自治州","红河哈尼族彝族自治州","文山壮族苗族自治州","西双版纳傣族自治州","大理白族自治州","德宏傣族景颇族自治州","怒江傈僳族自治州","迪庆藏族自治州"]},
{"n":"青海省","c":["西宁市","海东地区","海北藏族自治州","黄南藏族自治州","海南藏族自治州","果洛藏族自治州","玉树藏族自治州","海西蒙古族藏族自治州"]},
{"n":"陕西省","c":["西安市","铜川市","宝鸡市","咸阳市","渭南市","延安市","汉中市","榆林市","安康市","商洛市"]},
{"n":"广西壮族自治区","c":["南宁市","柳州市","桂林市","梧州市","北海市","防城港市","钦州市","贵港市","玉林市","百色市","贺州市","河池市","来宾市","崇左市"]},
{"n":"西藏自治区","c":["拉萨市","昌都地区","山南地区","日喀则地区","那曲地区","阿里地区","林芝地区"]},
{"n":"宁夏回族自治区","c":["银川市","石嘴山市","吴忠市","固原市","中卫市"]}];

$.initProv = function(prov, city, defaultProv, defaultCity) {
	var provEl = $(prov);
	var cityEl = $(city);
	var hasDefaultProv = (typeof(defaultCity) != 'undefined');
	
	var provHtml = '';
	
	provHtml += '<option value="-1">请选择</option>';
	for(var i = 0; i < $._cityInfo.length; i++) {
		provHtml += '<option value="' + i + '"' + ((hasDefaultProv && $._cityInfo[i].n == defaultProv) ? ' selected="selected"' : '') + '>' + $._cityInfo[i].n + '</option>';
	}
	provEl.html(provHtml);
	$.initCities(provEl, cityEl, defaultCity);
	provEl.change(function() {
		$.initCities(provEl, cityEl);
	});
};

$.initCities = function(provEl, cityEl, defaultCity) {
	var hasDefaultCity = (typeof(defaultCity) != 'undefined');
	if(provEl.val() != '' && parseInt(provEl.val()) >= 0) {
		var cities = $._cityInfo[parseInt(provEl.val())].c;
		var cityHtml = '';
		
		cityHtml += '<option value="-1">请选择</option>';
		for(var i = 0; i < cities.length; i++) {
			cityHtml += '<option value="' + i + '"' + ((hasDefaultCity && cities[i] == defaultCity) ? ' selected="selected"' : '') + '>' + cities[i] + '</option>';
		}
		cityEl.html(cityHtml);
	} else {
		cityEl.html('<option value="-1">请先选择</option>');
	}
};
分享到:
评论

相关推荐

    jQuery移动端省市二级联动选择插件.zip

    此插件基于jQuery,利用其强大的DOM操作和事件处理能力,实现了省市联动效果。当用户在省的选择项中做出选择时,插件会动态加载并更新市的选择项,这种实时同步的行为是通过监听省选择器的改变事件来实现的。这展示...

    省市区联动jquery插件

    标题中的“省市区联动jquery插件”是指一种用于网页开发的工具,主要用于处理用户在选择省份时,自动更新对应的市和区的选择项,以实现这三个级别行政区划的联动效果。这种插件通常能够提高用户体验,简化用户在填写...

    jquery省市区三级联动插件(数据全)

    这个“jquery省市区三级联动插件”是为了解决一个常见的前端开发需求——实现省市区选择的联动效果。这种功能常见于用户注册、地址填写等场景,能够提供用户友好的交互体验。 首先,我们要理解什么是“三级联动”。...

    js省市联动插件

    在网页开发中,省市联动插件是一个常见的功能需求,它主要用于用户输入地址时提供便捷的选择方式,例如在选择省份后自动加载对应的市和区。这种功能可以极大地提高用户体验,减少用户手动输入的负担。本插件是纯...

    jQuery json省市区街道四级联动地址选择插件.zip

    《jQuery JSON省市区街道四级联动地址选择插件详解》 在网页开发中,尤其是在涉及到用户信息填写时,省市区街道的选择通常是一个常见的需求。为了提高用户体验并简化开发工作,jQuery JSON省市区街道四级联动地址...

    HTML网页 jQuery移动端 省市区三级联动 城市选择插件

    在省市区联动插件中,jQuery可以用于监听用户的交互,如点击事件,然后根据用户的选择更新下拉菜单的选项。它还提供了一系列便捷的动画效果,使得用户在选择过程中有更好的视觉体验。 至于省市区三级联动,这是一种...

    jQuery--省市区联动插件

    总的来说,jQuery省市区联动插件是提高移动应用用户体验的重要工具,它结合了jQuery的便利性和动态数据的高效处理,使得地址选择变得简单而直观。通过理解其工作原理和实现方式,开发者可以快速地在自己的项目中部署...

    可初始化值的jQuery省市三级联动插件

    本文将深入探讨“可初始化值的jQuery省市三级联动插件”,这是一个能够帮助开发者实现动态选择省份、城市和区县的交互功能,并且能够预先设置默认值的插件。 首先,我们需要理解什么是“联动”或者“级联选择”。在...

    jQuery json省市区街道四级联动地址选择插件

    **jQuery JSON 省市区街道四级联动地址选择插件** 在网页开发中,尤其是在电子商务网站或者需要用户填写详细地址的应用中,四级联动地址选择插件是一个常见且实用的功能。它通常包括省、市、区(县)和街道四个级别...

    jQuery省市区三级联动插件_城市三级联动插件(原创).rar

    《jQuery省市区三级联动插件:城市选择的高效解决方案》 在网页开发中,省市区三级联动是一个常见的功能,尤其在注册、地址填写等场景下不可或缺。jQuery作为一款广泛使用的JavaScript库,为开发者提供了丰富的API...

    Jquery 省市县三级联动插件(三种总有一款适合你)

    这个插件可能是一个简单的省市县联动解决方案,基于jQuery构建。它的特点可能在于轻量级和易于集成。通常,这样的插件会包含一个JSON文件,存储了我国所有省市区县的名称和层级关系,通过Jquery的事件监听和DOM操作...

    jQuery五级联动插件

    **jQuery五级联动插件详解** 在Web开发中,我们经常需要实现地区选择功能,例如省市区县到街道的五级联动。这种功能能够帮助用户精确地定位他们的位置,尤其适用于电子商务、物流配送等场景。然而,对于大型的省...

    jQuery全国省市区三级联动插件.rar

    【jQuery全国省市区三级联动插件】是一种基于JavaScript库jQuery实现的前端交互功能,它能够为网站提供动态的、交互式的省市区选择下拉菜单。这个插件的主要目的是简化开发者在构建网页时处理地区选择的复杂性,通过...

    jquery省市县联动下拉框

    在网页开发中,"jQuery省市县联动下拉框"是一个常见的功能需求,它主要用于实现用户在选择省份时,对应的市和县下拉框能够自动更新,提供与所选省份匹配的选项。这种交互设计可以极大地提升用户体验,尤其在处理大量...

    jQuery省市区三级联动插件

    **jQuery省市区三级联动插件**是一种常见的前端开发技术,用于在网页上实现省、市、区(县)的联动选择效果。这种效果通常应用于地址输入、订单填写等场景,可以方便用户快速选择地理位置,提高用户体验。在...

    jQuery省市区三级联动插件city-picker

    **jQuery省市区三级联动插件city-picker详解** 在网页开发中,经常需要实现省市区三级联动的效果,即用户选择一个省份后,相应的城市列表自动更新,再选择城市时,对应的区县列表也会随之变化。这种功能可以提升...

    JQuery中国省市区街道三级、四级联动下拉菜单插件

    封装JQuery插件,中国省市区三级联动下拉菜单,省市区街道四级联动下拉菜单插件,三级插件取的值为地区编号或地区名,四级插件默认为地区编号,修改jquery.citys.js中的valueType为“name”,街道单独在代码中修改...

    district是一款jQuery多级下拉菜单联动插件

    district是一款专为jQuery设计的多级下拉菜单联动插件,它旨在简化在网页中创建交互式、层次化的菜单系统。这款插件的核心功能在于实现省市县等多级选择的联动效果,允许用户根据需要进行定制,以适应各种项目的需求...

    jQuery中国省市区城市选择三级联动插件

    【jQuery中国省市区城市选择三级联动插件】是一种常见的前端开发工具,主要用于在网页上实现用户选择省份、城市、区县的功能。这个插件利用了JavaScript库jQuery的强大功能,为用户提供了一个简洁、高效的交互体验。...

Global site tag (gtag.js) - Google Analytics