調接口省市區三級聯動相關代碼
//加載省份
$.ajax({
type: ‘GET‘,
url: "/cifcogroup/application/web/index.php?r=supply-chain-finance/choose-area&userId="+913555801+"&level=1&pid=0" ,
success: function (data) {
console.log(data);
if (data.status == true) {
var area=data.msg.areaInfos;
console.log(area);
for(var i=0;i<area.length;i++){
$("#province").append(
‘<option value="‘+area[i].areaId+‘">‘+area[i].areaName+‘</option>‘
)
}
}
if (data.status == false) {
var error = data.error.error_msg;
$(".layerbigb .titlemsg").text(error);
$(".layerbigb").css("display", "block");
return false
}
},
error: function (data) {
console.log(data.error.error_msg)
}
})
$.getUrlParam = function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]);
return null;
};
var userId = $.getUrlParam("userId");
var merchant_id=$.getUrlParam("merchant_id");
var region="";
var areaId=$(‘#province option:selected‘) .val();//省份id
var cityId=$(‘#city option:selected‘) .val();//省份id
$(‘.mainnew_check‘).find(‘input[type=checkbox]‘).bind(‘click‘, function() {
$(‘.mainnew_check‘).find(‘input[type=checkbox]‘).not(this).attr("checked", false);
if($("#ckb1").prop("checked")){
$("#handing_type").val("0")
}
if($("#ckb2").prop("checked")){
$("#handing_type").val("1")
}
console.log( $("#handing_type").val());
});
console.log( $("#handing_type").val());
var province = $("#province option:selected").text();
$(‘#province‘).change(function () {
province = $("#province option:selected").text();
console.log(province);
$(".p1").html(province);
areaId=$(‘#province option:selected‘) .val();
console.log(areaId);
$(".p2").html("市區");
$("#city").empty();
$(".p3").html("城區");
$("#county").empty();
$.ajax({
type: ‘GET‘,
url: "/cifcogroup/application/web/index.php?r=supply-chain-finance/choose-area&userId="+913555801+"&level=2&pid="+areaId ,
success: function (data) {
console.log(data);
if (data.status == true) {
var area=data.msg.areaInfos;
console.log(area);
/* for(var i=0;i<area.length;i++){
$("#city").append(
‘<option value="‘+area[i].areaId+‘">‘+area[i].areaName+‘</option>‘
)
}
var str="";
for(var i=0;i<area.length;i++){
str+= ‘<option value="‘+area[i].areaId+‘">‘+area[i].areaName+‘</option>‘;
}
//
$("#city").append(str);
}
if (data.status == false) {
var error = data.error.error_msg;
$(".layerbigb .titlemsg").text(error);
$(".layerbigb").css("display", "block");
return false
}
},
error: function (data) {
console.log(data.error.error_msg)
}
})
});
//獲取省份id
var city = $("#city option:selected").text();
$(‘#city‘).change(function () {
$(".p3").html("城區");
$("#county").empty();
city = $("#city option:selected").text();
console.log(city);
$(".p2").html(city);
cityId=$(‘#city option:selected‘) .val();
$.ajax({
type: ‘GET‘,
url: "/cifcogroup/application/web/index.php?r=supply-chain-finance/choose-area&userId="+913555801+"&level=3&pid="+cityId ,
success: function (data) {
console.log(data);
if (data.status == true) {
var area=data.msg.areaInfos;
console.log(area);
/* for(var i=0;i<area.length;i++){
$("#city").append(
‘<option value="‘+area[i].areaId+‘">‘+area[i].areaName+‘</option>‘
)
}*/
var str="";
for(var i=0;i<area.length;i++){
str+= ‘<option value="‘+area[i].areaId+‘">‘+area[i].areaName+‘</option>‘;
}
$("#county").append(str);
}
if (data.status == false) {
var error = data.error.error_msg;
$(".layerbigb .titlemsg").text(error);
$(".layerbigb").css("display", "block");
return false
}
},
error: function (data) {
console.log(data.error.error_msg)
}
})
});
var county = $("#county option:selected").text();
$(‘#county‘).change(function () {
county = $("#county option:selected").text();
console.log(county);
$(".p3").html(county)
region=""+province+city+county;
console.log(region)
});
console.log(region);
調接口省市區三級聯動相關代碼