- 通过地区编码初始化设置
- $('#demo').citys({code:350206});
复制代码- 通过地区名称初始化设置,并且下拉框值为地区名称
- $('#demo1').citys({valueType:'name',province:'福建',city:'厦门',area:'思明'});
复制代码- 事件处理
- $('#demo2').citys({
- required:false,
- nodata:'disabled',
- onChange:function(data){
- var text = data['direct']?'(直辖市)':'';
- $('#place').text('当前选中地区:'+data['province']+text+' '+data['city']+' '+data['area']);
- }
- });
复制代码- 扩展显示行政区划第四级(街道)信息:
- var $town = $('#demo3 select[name="town"]');
- var townFormat = function(info){
- $town.hide().empty();
- if(info['code']%1e4&&info['code']<7e6){ //是否为“区”且不是港澳台地区
- $.ajax({
- url:'http://passer-by.com/data_location/town/'+info['code']+'.json',
- dataType:'json',
- success:function(town){
- $town.show();
- for(i in town){
- $town.append('<option value="'+i+'">'+town[i]+'</option>');
- }
- }
- });
- }
- };
- $('#demo3').citys({
- province:'福建',
- city:'厦门',
- area:'思明',
- onChange:function(info){
- townFormat(info);
- }
- },function(api){
- var info = api.getInfo();
- townFormat(info);
- });
复制代码- 调用方法:
- $(selector).citys(options,callback);
复制代码
|