lizhen_gitee 5a2b1d27f5 被忽略的 | hai 7 meses | |
---|---|---|
.. | ||
dist | hai 7 meses | |
src | hai 7 meses | |
.bower.json | hai 7 meses | |
CHANGELOG.md | hai 7 meses | |
LICENSE | hai 7 meses | |
README.md | hai 7 meses | |
bower.json | hai 7 meses | |
gulpfile.js | hai 7 meses | |
package.json | hai 7 meses |
A simple jQuery plugin for picking provinces, cities and districts of China.
##Release History
###v1.1.0 Add function to get the code:
// type: null or undefined(get the full code path, separated with /), province, city, district
$('.city-picker').data('citypicker').getCode(type);
dist/
├── city-picker.js ( 7 KB)
├── city-picker.min.js ( 4 KB)
├── city-picker.data.js (98 KB)
└── city-picker.data.min.js (68 KB)
Four quick start options are available:
git clone https://github.com/tshi0912/city-picker.git
.npm install city-picker
.bower install city-picker
.Include files:
<script src="/path/to/jquery.js"></script><!-- jQuery is required -->
<script src="/path/to/city-picker.data.js"></script>
<script src="/path/to/city-picker.js"></script>
Create HTML elements:
<div style="position:relative;"><!-- container -->
<input readonly type="text">
</div>
data-toggle="city-picker"
attributeBasic
<div style="position:relative;">
<input readonly type="text" data-toggle="city-picker">
</div>
Custom placeholders
<div style="position:relative;">
<input readonly type="text" data-toggle="city-picker" placeholder="customized placeholder...">
</div>
Responsive width
<div style="position:relative;">
<input readonly type="text" data-toggle="city-picker" data-responsive="true" style="width:50%;">
</div>
Custom province/city/district
<div style="position:relative;">
<input readonly type="text" data-toggle="city-picker" value="江苏省/常州市/溧阳市">
</div>
$.fn.city-picker
methodBasic
$('#target').citypicker();
Custom districts
$('#target').citypicker({
province: '江苏省',
city: '常州市',
district: '溧阳市'
});
$().citypicker(options)
.$.fn.citypicker.setDefaults(options)
.Boolean
false
Make the address level more simple, e.g. 内蒙古
instead of 内蒙古自治区
.
String
district
Only province, province + city, or province + city + district.
Boolean
false
make the drop down and mask span responsive on width.
Boolean
请输入省/市/区
Show placeholder (with an <option>
element).
String
null
Defines the initial value of province. If it is a existing province in city-picker.data.js
, it will be selected. If not, it will be used as a placeholder.
String
null
Defines the initial value of city. If it is a existing city under the selected province, it will be selected. If not, it will be used as a placeholder.
String
null
Defines the initial value of district. If it is a existing district under the selected city, it will be selected. If not, it will be used as a placeholder.
Reset the selects to the initial states (Undo changed).
Examples:
$().citypicker('reset');
Destroy the city-picker 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.
If you have to use other plugin with the same namespace, just call the $.fn.city-picker.noConflict
method to revert to it.
<script src="other-plugin.js"></script>
<script src="city-picker.js"></script>
<script>
$.fn.citypicker.noConflict();
// Code that uses other plugin's "$().citypicker" can follow here.
</script>
As a jQuery plugin, you also need to see the jQuery Browser Support.