审查视图

public/assets/libs/fastadmin-citypicker/README.md 4.4 KB
王智 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
# City Picker

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

- [Demo](http://tshi0912.github.io/city-picker)

##Release History

###v1.1.0
Add function to get the code:

```javascript
// type: null or undefined(get the full code path, separated with /), province, city, district
$('.city-picker').data('citypicker').getCode(type);
```

## Main

```
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)
```



## Getting started


### Quick start

Four quick start options are available:

- [Download the latest release](https://github.com/tshi0912/city-picker/archive/master.zip).
- Clone the repository: `git clone https://github.com/tshi0912/city-picker.git`.
- Install with [NPM](http://npmjs.org): `npm install city-picker`.
- Install with [Bower](http://bower.io): `bower install city-picker`.


### Installation

Include files:

```html
<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:

```html
<div style="position:relative;"><!-- container -->
  <input readonly type="text">
</div>
```



### Usage

#### Initialize with `data-toggle="city-picker"` attribute


Basic

```html
<div style="position:relative;">
  <input readonly type="text" data-toggle="city-picker">
</div>
```


Custom placeholders

```html
<div style="position:relative;">
  <input readonly type="text" data-toggle="city-picker" placeholder="customized placeholder...">
</div>
```

Responsive width

```html
<div style="position:relative;">
  <input readonly type="text" data-toggle="city-picker" data-responsive="true" style="width:50%;">
</div>
```


Custom province/city/district

```html
<div style="position:relative;">
  <input readonly type="text" data-toggle="city-picker" value="江苏省/常州市/溧阳市">
</div>
```


#### Initialize with `$.fn.city-picker` method

Basic

```js
$('#target').citypicker();
```

Custom districts

```js
$('#target').citypicker({
  province: '江苏省',
  city: '常州市',
  district: '溧阳市'
});
```



## Options

- Change the default options with `$().citypicker(options)`.
- Change the global default options with `$.fn.citypicker.setDefaults(options)`.


### simple

- Type: `Boolean`
- Default: `false`

Make the address level more simple, e.g. `内蒙古` instead of `内蒙古自治区`.

### level

- Type: `String`
- Default: `district`

Only province, province + city, or province + city + district.

### responsive

- Type: `Boolean`
- Default: `false`

make the drop down and mask span responsive on width.

### placeholder

- Type: `Boolean`
- Default: `请输入省/市/区`

Show placeholder (with an `<option>` element).


### province

- Type: `String`
- Default: `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.


### city

- Type: `String`
- Default: `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.


### district

- Type: `String`
- Default: `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.



## Methods

### reset()

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

**Examples:**

```js
$().citypicker('reset');
```

### destroy()

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.



## No conflict

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

```html
<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>
```



## 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](http://jquery.com/browser-support/).



## License

[MIT](http://opensource.org/licenses/MIT) © [Tao Shi](http://shitao.me)