A simple jQuery plugin for picking provinces, cities and districts of China.
Html:
<div id="cncity" class="form-group">
<select data-placeholder = "-请选择-" class="form-control">
</select>
<select data-placeholder = "-请选择-" class="form-control">
</select>
<select data-placeholder = "-请选择-" class="form-control">
</select>
</div>
Javascript:
<script src="https://cdn.bootcss.com/jquery/2.2.2/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="./js/jquery.bs.cncitypicker.js"></script>
Usage:
var city = $('#cncity').cncitypicker();
是否自动从url获取省市区参数code选中相应select,默认:false
设置从url获取省市区参数code对应的参数名,object键值对如下:
{
province_param:'province',
city_param:'city',
district_param:'district'
}
是否验证select是否已经选中值,默认:false
设置省的默认值code和未选中时的提示,object键值对如下:
{
code:'',
placeholder:'-请选择省-'
}
设置市的默认值code和未选中时的提示,object键值对如下:
{
code:'',
placeholder:'-请选择市-'
}
设置区的默认值code和未选中时的提示,object键值对如下:
{
code:'',
placeholder:'-请选择市-'
}
根据code获取相应名称城市
获取选中的代码和名称
根据区县code获取所在的省和市
从url中获取参数是param的值
当改变省份时触发事件
当改变城市时触发事件
当改变区域时触发事件
eg:
$('#cncity').cncitypicker({
onProvinceChange:function(){
},
onCityChange:function(){
},
onDistrictChange:function(){
}
});