A jQuery plugin for picking provinces, cities and districts of China.
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
.
Include files:
<script src="/path/to/jquery.js"></script><!-- jQuery is required -->
<script src="/path/to/distpicker.data.js"></script>
<script src="/path/to/distpicker.js"></script>
Create HTML elements:
<div><!-- container -->
<select></select><!-- province -->
<select></select><!-- city -->
<select></select><!-- district -->
</div>
<div data-toggle="distpicker">
<select></select>
<select></select>
<select></select>
</div>
<div data-toggle="distpicker">
<select data-province="---- 选择省 ----"></select>
<select data-city="---- 选择市 ----"></select>
<select data-district="---- 选择区 ----"></select>
</div>
<div data-toggle="distpicker">
<select data-province="北京"></select>
<select data-city="北京市"></select>
<select data-district="海淀区"></select>
</div>
$('#target').distpicker();
$('#target').distpicker({
province: '---- 所在省 ----',
city: '---- 所在市 ----',
district: '---- 所在区 ----'
});
$('#target').distpicker({
province: '北京',
city: '北京市',
district: '海淀区'
});
- Change the default options with
$().distpicker(options)
. - Change the global default options with
$.fn.distpicker.setDefaults(options)
.
- Type:
Boolean
- Default:
true
Selects the city and district automatically when the province changes.
- Type:
Boolean
- Default:
true
Show placeholder option.
- 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.
- 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.
- 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.
Params | Type | Default | Description |
---|---|---|---|
deep | Boolean |
false |
Undo selected |
Reset the selects to the initial state (Undo changed).
Examples:
$().distpicker('reset')
$().distpicker('reset', true)
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.
- Chrome 33+
- Firefox 27+
- Internet Explorer 6+
- Opera 19+
- Safari 5.1+
As a jQuery plugin, you can reference to the jQuery Browser Support.
Released under the MIT license.