Distpicker
A simple jQuery plugin for picking provinces, cities and districts of China.
Main
dist/
├── distpicker.js ( 7 KB)
├── distpicker.min.js ( 4 KB)
├── distpicker.data.js (110 KB)
└── distpicker.data.min.js ( 76 KB)
Getting started
Quick start
Four quick start options are available:
- Download the latest release.
- Clone the repository:
git clone https://github.com/fengyuanchen/distpicker.git
. - Install with NPM:
npm install distpicker
. - Install with Bower:
bower install distpicker
.
Installation
Include files:
<!-- jQuery is required -->
Create HTML elements:
<!-- container --> <!-- province --> <!-- city --> <!-- district -->
Usage
data-toggle="distpicker"
attribute
Initialize with Basic
Custom placeholders
Custom districts
$.fn.distpicker
method
Initialize with Basic
;
Custom placeholders
;
Custom districts
;
Options
- Change the default options with
$().distpicker(options)
. - Change the global default options with
$.fn.distpicker.setDefaults(options)
.
autoSelect
- Type:
Boolean
- Default:
true
Selects the city and district automatically when the province changes.
placeholder
- Type:
Boolean
- Default:
true
Show placeholder (with an <option>
element).
province
- Type:
String
- Default:
—— 省 ——
Defines the initial value of province <select>
. If it is a existing province in distpicker.data.js
, 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 existing 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 existing district under the selected city, it will be selected. If not, it will be used as a placeholder.
Methods
reset([deep])
- deep (optional):
- Type:
Boolean
- Default:
false
- Reset the selects to default states (Undo selected).
- Type:
Reset the selects to the initial states (Undo changed).
Examples:
;;
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.
No conflict
If you have to use other plugin with the same namespace, just call the $.fn.distpicker.noConflict
method to revert to it.
Browser support
- Chrome (latest 2)
- Firefox (latest 2)
- Internet Explorer 8+
- Opera (latest 2)
- Safari (latest 2)
As a jQuery plugin, you also need to see the jQuery Browser Support.