All Projects → fengyuanchen → Distpicker

fengyuanchen / Distpicker

Licence: mit
⚠️ [Deprecated] No longer maintained. A simple jQuery plugin for picking provinces, cities and districts of China. (中国 / 省市区 / 三级联动 / 地址选择器)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Distpicker

Colorpicker
jQuery UI widget for color picking (similar to the one in Microsoft Office 2010).
Stars: ✭ 271 (-83.15%)
Mutual labels:  jquery-plugin, picker
jquery-datepicker
A full-featured datepicker jquery plugin
Stars: ✭ 35 (-97.82%)
Mutual labels:  jquery-plugin, picker
Datetimepicker
jQuery Plugin Date and Time Picker
Stars: ✭ 3,402 (+111.57%)
Mutual labels:  jquery-plugin, picker
react-area-linkage
省市区联动选择: https://dwqs.github.io/react-area-linkage/
Stars: ✭ 52 (-96.77%)
Mutual labels:  picker, china
Vue Area Linkage
省市区联动选择: https://dwqs.github.io/vue-area-linkage/
Stars: ✭ 439 (-72.7%)
Mutual labels:  china, picker
Anypicker
jQuery Picker Library for Android, iOS & Windows Phone. eg Date Picker, Time Picker, DateTime Picker, Custom Select etc
Stars: ✭ 114 (-92.91%)
Mutual labels:  picker
Calendar
📆 calendar 日历
Stars: ✭ 119 (-92.6%)
Mutual labels:  picker
React Native Form Builder
Handle your forms in a smart way
Stars: ✭ 113 (-92.97%)
Mutual labels:  picker
Brickyeditor
WYSIWYG block editor jQuery plugin.
Stars: ✭ 112 (-93.03%)
Mutual labels:  jquery-plugin
Jquery Filepond
🔌 A handy FilePond wrapper for jQuery
Stars: ✭ 124 (-92.29%)
Mutual labels:  jquery-plugin
Fotorama
A simple, stunning, powerful jQuery gallery.
Stars: ✭ 1,567 (-2.55%)
Mutual labels:  jquery-plugin
Datepicker
仿滴滴出行预约打车IOS风格3D时间选择器 🌲
Stars: ✭ 118 (-92.66%)
Mutual labels:  picker
Isonscreen
Simple jQuery plugin to determine if an element is within the viewport
Stars: ✭ 115 (-92.85%)
Mutual labels:  jquery-plugin
Toast
A Bootstrap 4.2+ jQuery plugin for the toast component
Stars: ✭ 121 (-92.48%)
Mutual labels:  jquery-plugin
Jquery Rwdimagemaps
Responsive Image Maps jQuery Plugin
Stars: ✭ 1,511 (-6.03%)
Mutual labels:  jquery-plugin
Jquery Syntaxhighlighter
jQuery Extension for Google's Prettify Syntax Highlighter
Stars: ✭ 123 (-92.35%)
Mutual labels:  jquery-plugin
Slickquiz
A jQuery plugin for creating pretty, dynamic quizzes.
Stars: ✭ 112 (-93.03%)
Mutual labels:  jquery-plugin
Administrative Divisions Of China
中华人民共和国行政区划:省级(省份直辖市自治区)、 地级(城市)、 县级(区县)、 乡级(乡镇街道)、 村级(村委会居委会) ,中国省市区镇村二级三级四级五级联动地址数据。
Stars: ✭ 11,727 (+629.29%)
Mutual labels:  china
Belvedere
An image picker library for Android
Stars: ✭ 122 (-92.41%)
Mutual labels:  picker
Articulate.js
A jQuery plugin that lets the browser speak to you.
Stars: ✭ 116 (-92.79%)
Mutual labels:  jquery-plugin

Distpicker

Downloads Version Gzip Size

A simple jQuery plugin for picking provinces, cities and districts of China.

请注意以下市/县并未设置下一级的区:济源市、潜江市、神农架林区、天门市、仙桃市、东莞市、中山市、东沙群岛、白沙黎族自治县、保亭黎族苗族自治县、昌江黎族自治县、澄迈县、儋州市、定安县、东方市、乐东黎族自治县、临高县、陵水黎族自治县、琼海市、琼中黎族苗族自治县、屯昌县、万宁市、文昌市、五指山市、嘉峪关市、阿拉尔市、北屯市、可克达拉市、昆玉市、石河子市、双河市、铁门关市、图木舒克市、五家渠市。

Table of contents

Main

dist/
├── distpicker.js        (UMD)
├── distpicker.min.js    (UMD, compressed)
├── distpicker.common.js (CommonJS, default)
└── distpicker.esm.js    (ES Module)

Getting started

Install

npm install distpicker

Include files:

<script src="/path/to/jquery.js"></script><!-- jQuery is required -->
<script src="/path/to/distpicker.js"></script>

Create HTML elements:

<div><!-- container -->
  <select></select><!-- province -->
  <select></select><!-- city -->
  <select></select><!-- district -->
</div>

Usage

Initialize with data-toggle="distpicker" attribute

Basic

<div data-toggle="distpicker">
  <select></select>
  <select></select>
  <select></select>
</div>

Custom placeholders

<div data-toggle="distpicker">
  <select data-province="---- 选择省 ----"></select>
  <select data-city="---- 选择市 ----"></select>
  <select data-district="---- 选择区 ----"></select>
</div>

Custom districts

<div data-toggle="distpicker">
  <select data-province="浙江省"></select>
  <select data-city="杭州市"></select>
  <select data-district="西湖区"></select>
</div>

Initialize with $.fn.distpicker method

Basic

$('#target').distpicker();

Custom placeholders

$('#target').distpicker({
  province: '---- 所在省 ----',
  city: '---- 所在市 ----',
  district: '---- 所在区 ----'
});

Custom districts

$('#target').distpicker({
  province: '浙江省',
  city: '杭州市',
  district: '西湖区'
});

back to top

Options

  • Change the default options with $().distpicker(options).
  • Change the global default options with $.fn.distpicker.setDefaults(options).

Also supports to set the options by data-* attributes:

<div data-toggle="distpicker" data-autoselect="3" data-province="浙江省">...</div>

autoselect

  • Type: Number
  • Options:
    • 0: Disable autoselect.
    • 1: Autoselect province only.
    • 2: Autoselect province and city only.
    • 3: Autoselect all (province, city and district).
  • Default: 0

Selects the districts automatically.

placeholder

  • Type: Boolean
  • Default: true

Show placeholder (with an <option> element).

valueType

  • Type: String
  • Options:
    • 'name': administrative division name.
    • 'code': administrative division code.
  • Default: 'name'

Defines the value type of the <select> element.

Note that this option in data-* attribute should be data-value-type:

<div data-toggle="distpicker" data-value-type="code">...</div>

province

  • Type: String
  • Default: —— 省 ——

Defines the initial value of province <select>. If it is a valid province, it will be selected. If not, it will be used as a placeholder.

city

  • Type: String
  • Default: —— 市 ——

Defines the initial value of city <select>. If it is a valid city under the selected province, it will be selected. If not, it will be used as a placeholder.

district

  • Type: String
  • Default: —— 区 ——

Defines the initial value of district <select>. If it is a valid district under the selected city, it will be selected. If not, it will be used as a placeholder.

back to top

Methods

getDistricts([districtCode])

  • districtCode (optional):

    • Type: Number
    • The district code of target country, province or city.
    • If not present, will return all the districts.
  • (return value):

    • Type: Object

Get districts data.

$().distpicker('getDistricts'); // 中国
$().distpicker('getDistricts', 330000); // 浙江省
$().distpicker('getDistricts', 330100); // 杭州市

reset([deep])

  • deep (optional):
    • Type: Boolean
    • Default: false
    • Reset the selects to default states (Undo selected).

Reset the selects to the initial states (Undo changed).

$().distpicker('reset');
$().distpicker('reset', true);

destroy()

Destroy the distpicker instance, but keep the selected districts.

If you want to remove the selected districts, you can call reset method first and then call this method.

back to top

No conflict

If you have to use other plugin with the same namespace, just call the $.fn.distpicker.noConflict method to revert to it.

<script src="other-plugin.js"></script>
<script src="distpicker.js"></script>
<script>
  $.fn.distpicker.noConflict();
  // Code that uses other plugin's "$().distpicker" can follow here.
</script>

Browser support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Opera (latest)
  • Edge (latest)
  • Internet Explorer 9+

As a jQuery plugin, you also need to see the jQuery Browser Support.

License

MIT © Chen Fengyuan

back to top

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].