var http_host = 'api.school51.com';
//省市县联动选择:
var province_city_area = {
cfg:{
val_type:1,
province_select_name:'select_province',
city_select_name:'select_city',
area_select_name:'select_area',
province_val:'',
city_val:'',
area_val:''
},
//val_type:输出选项,1输出标识码,2输出汉字
//province_select_name:省份下拉框名称
//city_select_name:城市下拉框名称
//area_select_name:县下拉框名称
//province_val:省默认值
//city_val:城市默认值
//area_val:县默认值
show:function(val_type,province_val,city_val,area_val,province_select_name,city_select_name,area_select_name,other_cfg){
//存储传输值:
if(val_type)province_city_area.cfg.val_type = val_type;
if(province_select_name)province_city_area.cfg.province_select_name = province_select_name;
if(city_select_name)province_city_area.cfg.city_select_name = city_select_name;
if(area_select_name)province_city_area.cfg.area_select_name = area_select_name;
if(province_val)province_city_area.cfg.province_val = province_val;
if(city_val)province_city_area.cfg.city_val = city_val;
if(area_val)province_city_area.cfg.area_val = area_val;
//其他配置项:
if(other_cfg){
$.each(other_cfg,function(key,val){
province_city_area.cfg[key] = val;
});
}
//下拉框样式:
var select_class = 'select school_input';
if(province_city_area.cfg['class']){
select_class = province_city_area.cfg['class'];
}
//是否直接输出:
var is_write = 1;
if(province_city_area.cfg['write']){
is_write = province_city_area.cfg['write'];
}
//输出DOM
var _dom = ' ';
_dom += ' ';
if(province_city_area.cfg.area_select_name=="null"){
var area_style = ' style="display:none;"';
province_city_area.cfg.area_select_name = 'select_area';
}else{
var area_style = '';
}
_dom += ' ';
if(is_write==1){
document.write(_dom);
province_city_area.load_province();
}else{
window.setTimeout(function(){
province_city_area.load_province();
},200);
return _dom;
}
},
load_province:function(){
$.getJSON("http://" + http_host + "/hometown/get_province?jsoncallback=?",function(json){
if(json.status==1){
var select_html = "";
select_html += '';
for(var i = 0;i' + json.data[i].province + '';
}
$("#" + province_city_area.cfg.province_select_name).html(select_html);
//如果有默认值,进行下面的触发:
if(province_city_area.cfg.province_val){
$("#"+province_city_area.cfg.province_select_name).val(province_city_area.cfg.province_val);
province_city_area.change_province(true);
}
}
});
},
change_province:function(is_val){
var province_code = $("#"+province_city_area.cfg.province_select_name + " option:selected").attr('province_code');
$.getJSON("http://" + http_host + "/hometown/get_city?jsoncallback=?",{"province_code":province_code},function(json){
if(json.status==1){
var select_html = "";
select_html += '';
for(var i = 0;i' + json.data[i].city + '';
}
$("#"+province_city_area.cfg.city_select_name).html(select_html);
//如果有默认值,进行下面的触发:
if(province_city_area.cfg.city_val&&is_val){
$("#"+province_city_area.cfg.city_select_name).val(province_city_area.cfg.city_val);
province_city_area.change_city(true);
}else{
$("#"+province_city_area.cfg.area_select_name).html('');
}
}
});
},
change_city:function(is_val){
var city_code = $("#"+province_city_area.cfg.city_select_name + " option:selected").attr('city_code');
$.getJSON("http://" + http_host + "/hometown/get_area?jsoncallback=?",{"city_code":city_code},function(json){
if(json.status==1){
var select_html = "";
select_html += '';
for(var i = 0;i' + json.data[i].area + '';
}
$("#"+province_city_area.cfg.area_select_name).html(select_html);
//如果有默认值,进行下面的触发:
if(province_city_area.cfg.area_val&&is_val){
$("#"+province_city_area.cfg.area_select_name).val(province_city_area.cfg.area_val);
}
}
});
}
};