码迷,mamicode.com
首页 > Web开发 > 详细

JS 省市县小区联动

时间:2017-05-15 14:09:59      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:省份   content   getx   style   ict   charset   comm   json   .text   

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 省市县小区联动

标签:省份   content   getx   style   ict   charset   comm   json   .text   

原文地址:http://www.cnblogs.com/wc918/p/6855958.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!