JS 省市县小区联动
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS 省市县小区联动相关的知识,希望对你有一定的参考价值。
function ShengList() { //alert("准备展示省份并调用市"); $.ajax({ url: ‘/City/GetProvcnList‘, dataType: ‘json‘, contentType: ‘application/json;charset=utf-8‘, success: function (data) { var ProvcnStr = ""; $("#CityAreaIds").html(""); $.each(data, function (i, o) { ProvcnStr += ‘<option>‘ + o.provcn + ‘</option>‘; }); $("#CityAreaIds").html(ProvcnStr); ShiList($("#CityAreaIds").find("option:selected").text()); } }); }; function ShiList(provcn) { //alert("准备展示市区并调用县"); $.ajax({ data: { "provcn": provcn }, url: ‘/City/GetCitylist‘, dataType: ‘json‘, contentType: ‘application/json;charset=utf-8‘, success: function (data) { var districtcnStr = ""; $("#City").html(""); $.each(data, function (i, o) { districtcnStr += ‘<option>‘ + o.districtcn + ‘</option>‘; }); $("#City").html(districtcnStr); XianList($("#City").find("option:selected").text()); } }); }; function XianList(districtcn) { //alert("准备展示县区"); $.ajax({ data: { "districtcn": districtcn }, url: ‘/City/GetXanlist‘, dataType: ‘json‘, contentType: ‘application/json;charset=utf-8‘, success: function (data) { var namecnStr = ""; $("#CityAreaId").html(""); $.each(data, function (i, o) { namecnStr += ‘<option value=‘ + o.areaid + ‘ >‘ + o.namecn + ‘</option>‘; }); $("#CityAreaId").html(namecnStr); judge($(‘#CityAreaId option:selected‘).val()); //getXhpro($(‘#CityAreaId option:selected‘).val()); } }); }; function judge(CityAreaId) {//根据县查询所有的小区 $.ajax({ url: ‘/City/GetVillagnamelist‘, dataType: ‘json‘, data: { "city_areaid": CityAreaId }, contentType: ‘application/json;charset=utf-8‘, success: function (data) { var xiaoquStr = ""; $("#Community").html(""); $.each(data, function (i, o) { xiaoquStr += ‘<option value=‘ + o.id + ‘>‘ + o.name + ‘</option>‘; }); $("#Community").html(xiaoquStr); } }); }; $(function () { ShengList(); $("#CityAreaIds").change(function () { ShiList($(this).val()); }); $("#City").change(function () { XianList($(‘#City option:selected‘).text()); }); $("#CityAreaId").change(function () { judge($(‘#CityAreaId option:selected‘).val()); getXhpro($(this).val()); }); });
以上是关于JS 省市县小区联动的主要内容,如果未能解决你的问题,请参考以下文章