Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

README.md 4.4 KiB

il y a 4 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. # City Picker
  2. > A simple jQuery plugin for picking provinces, cities and districts of China.
  3. - [Demo](http://tshi0912.github.io/city-picker)
  4. ##Release History
  5. ###v1.1.0
  6. Add function to get the code:
  7. ```javascript
  8. // type: null or undefined(get the full code path, separated with /), province, city, district
  9. $('.city-picker').data('citypicker').getCode(type);
  10. ```
  11. ## Main
  12. ```
  13. dist/
  14. ├── city-picker.js ( 7 KB)
  15. ├── city-picker.min.js ( 4 KB)
  16. ├── city-picker.data.js (98 KB)
  17. └── city-picker.data.min.js (68 KB)
  18. ```
  19. ## Getting started
  20. ### Quick start
  21. Four quick start options are available:
  22. - [Download the latest release](https://github.com/tshi0912/city-picker/archive/master.zip).
  23. - Clone the repository: `git clone https://github.com/tshi0912/city-picker.git`.
  24. - Install with [NPM](http://npmjs.org): `npm install city-picker`.
  25. - Install with [Bower](http://bower.io): `bower install city-picker`.
  26. ### Installation
  27. Include files:
  28. ```html
  29. <script src="/path/to/jquery.js"></script><!-- jQuery is required -->
  30. <script src="/path/to/city-picker.data.js"></script>
  31. <script src="/path/to/city-picker.js"></script>
  32. ```
  33. Create HTML elements:
  34. ```html
  35. <div style="position:relative;"><!-- container -->
  36. <input readonly type="text">
  37. </div>
  38. ```
  39. ### Usage
  40. #### Initialize with `data-toggle="city-picker"` attribute
  41. Basic
  42. ```html
  43. <div style="position:relative;">
  44. <input readonly type="text" data-toggle="city-picker">
  45. </div>
  46. ```
  47. Custom placeholders
  48. ```html
  49. <div style="position:relative;">
  50. <input readonly type="text" data-toggle="city-picker" placeholder="customized placeholder...">
  51. </div>
  52. ```
  53. Responsive width
  54. ```html
  55. <div style="position:relative;">
  56. <input readonly type="text" data-toggle="city-picker" data-responsive="true" style="width:50%;">
  57. </div>
  58. ```
  59. Custom province/city/district
  60. ```html
  61. <div style="position:relative;">
  62. <input readonly type="text" data-toggle="city-picker" value="江苏省/常州市/溧阳市">
  63. </div>
  64. ```
  65. #### Initialize with `$.fn.city-picker` method
  66. Basic
  67. ```js
  68. $('#target').citypicker();
  69. ```
  70. Custom districts
  71. ```js
  72. $('#target').citypicker({
  73. province: '江苏省',
  74. city: '常州市',
  75. district: '溧阳市'
  76. });
  77. ```
  78. ## Options
  79. - Change the default options with `$().citypicker(options)`.
  80. - Change the global default options with `$.fn.citypicker.setDefaults(options)`.
  81. ### simple
  82. - Type: `Boolean`
  83. - Default: `false`
  84. Make the address level more simple, e.g. `内蒙古` instead of `内蒙古自治区`.
  85. ### level
  86. - Type: `String`
  87. - Default: `district`
  88. Only province, province + city, or province + city + district.
  89. ### responsive
  90. - Type: `Boolean`
  91. - Default: `false`
  92. make the drop down and mask span responsive on width.
  93. ### placeholder
  94. - Type: `Boolean`
  95. - Default: `请输入省/市/区`
  96. Show placeholder (with an `<option>` element).
  97. ### province
  98. - Type: `String`
  99. - Default: `null`
  100. 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.
  101. ### city
  102. - Type: `String`
  103. - Default: `null`
  104. 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.
  105. ### district
  106. - Type: `String`
  107. - Default: `null`
  108. 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.
  109. ## Methods
  110. ### reset()
  111. Reset the selects to the initial states (Undo changed).
  112. **Examples:**
  113. ```js
  114. $().citypicker('reset');
  115. ```
  116. ### destroy()
  117. Destroy the city-picker instance, but keep the selected districts.
  118. If you want to remove the selected districts, you can call `reset` method first and then call this method.
  119. ## No conflict
  120. If you have to use other plugin with the same namespace, just call the `$.fn.city-picker.noConflict` method to revert to it.
  121. ```html
  122. <script src="other-plugin.js"></script>
  123. <script src="city-picker.js"></script>
  124. <script>
  125. $.fn.citypicker.noConflict();
  126. // Code that uses other plugin's "$().citypicker" can follow here.
  127. </script>
  128. ```
  129. ## Browser support
  130. - Chrome (latest 2)
  131. - Firefox (latest 2)
  132. - Internet Explorer 8+
  133. - Opera (latest 2)
  134. - Safari (latest 2)
  135. As a jQuery plugin, you also need to see the [jQuery Browser Support](http://jquery.com/browser-support/).
  136. ## License
  137. [MIT](http://opensource.org/licenses/MIT) © [Tao Shi](http://shitao.me)