根据传来的省市县乡值实现自动填充的四级联动

if (provinceId != '' && provinceId != null && provinceId != 'null') {
$('#provinceId').val(provinceId);
signupRecordObj.getCity(provinceId,cityId,countyId,townId);
}
"getCity":function (provinceId,cityId,countryId,townId) {/*根据省获取城市信息*/
var cityObj = {url: configJS.hostUrl() + '/province/citys', async: false, param:{"provinceId":provinceId},method:"GET"};
commonJS.sendAjaxRequest(cityObj, function (value) {/*初始化省信息*/
$("#cityId").html("<option value='' >市</option>");
if (value != null && value.body != null) {
$($("#city_template").render(value.body)).appendTo("#cityId");
if (cityId != null && cityId != null && cityId != 'null') {
$("#cityId").val(cityId);
signupRecordObj.getCounty(cityId,countryId,townId);
}
}
});
},
"getCounty":function (cityId,countyId,townId) {/*根据城市获取区县信息*/
var countyObj = {url: configJS.hostUrl() + '/province/countys', async: false, param:{"cityId":cityId},method:"GET"};
commonJS.sendAjaxRequest(countyObj, function (value) {/*初始化市信息*/
$("#countyId").html("<option value='' >区/县</option>");
if (value != null && value.body != null) {
$($("#county_template").render(value.body)).appendTo("#countyId");
if (countyId != null && countyId != null && countyId != 'null') {
$("#countyId").val(countyId);
signupRecordObj.getTown(countyId,townId);
}
}
});
},
"getTown":function (countyId,townId) {/*根据区县获取乡镇信息*/
var townObj = {url: configJS.hostUrl() + '/province/towns', async: false, param:{"countyId":countyId},method:"GET"};
commonJS.sendAjaxRequest(townObj, function (value) {/*初始化区县信息*/
$("#townId").html("<option value='' >乡/镇</option>");
if (value != null && value.body != null) {
$($("#town_template").render(value.body)).appendTo("#townId");
if (townId != null && townId != '' && townId != 'null') {
$("#townId").val(townId);
}
}
});
},
posted @ 2016-12-08 11:41  lcpnene  阅读(1080)  评论(0编辑  收藏  举报