// 省市切换
province = {
// template
/* -------------------------------------------------------------
-------------------------------------------------------------*/
url_province: site_url + 'province/province_ajax'
,url_province_city: site_url + 'province/city_ajax'
,init:function(pv){
l = arguments[1]?arguments[1]:0;
$.ajax({
url:this.url_province
,type:'get'
,datatype:'json'
})
.done(function(data){
op = '';
$.each(data,function(index, el) {
if (l && l.province == el.id) {
op += '';
});
console.log(op);
pv.append(op);
});
_city = pv.next('.province_city');
if (l) {
province.get_city(l.province,_city,l.city);
}else{
province.get_city(1,_city);
}
// 省选择进行处理
$(pv).on('change', function(event) {
pid = $(this).val();
_province = $(this);
_city = $(this).next('.province_city');
province.get_city(pid,_city);
});
}
// pid 省id city为city select的对象
,get_city:function(pid,city){
lc = arguments[2]?arguments[2]:0;
$.ajax({
url:this.url_province_city
,type:'get'
,datatype:'json'
,data:{pid:pid}
})
.done(function(data){
op = '';
$.each(data,function(index, el) {
if (lc && lc == el.id) {
op += '';
});
city.html('');
city.append(op);
});
}
};