基本信息
源码名称:jquery 城市三级联动例子下载
源码大小:0.05M
文件格式:.zip
开发语言:C#
更新时间:2016-01-22
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

城市三级联动

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript">
        $(function (test) {
            var test =
            [
            { "_alevel": 0, "_areaname": "中华人民共和国", "_id": 1, "_ordernum": null, "_parentid": 0 },
            { "_alevel": 1, "_areaname": "北京市", "_id": 2, "_ordernum": null, "_parentid": 1 },
            { "_alevel": 1, "_areaname": "江苏省", "_id": 3, "_ordernum": null, "_parentid": 1 },
            { "_alevel": 2, "_areaname": "淮安市", "_id": 5, "_ordernum": null, "_parentid": 3 },
            { "_alevel": 3, "_areaname": "淮阴区", "_id": 6, "_ordernum": null, "_parentid": 5 },
            { "_alevel": 2, "_areaname": "南京市", "_id": 9, "_ordernum": null, "_parentid": 3 }
            ]
            var province = [];//省
            var city = [];//市
            var district = [];//县
            for (var i = 0; i < test.length; i  ) {
                var level = parseInt(test[i]._alevel);
                if (level == 1) {
                    province.push(test[i]);
                } else if (level == 2) {
                    city.push(test[i]);
                } else if (level == 3 && level != 0) {
                    district.push(test[i]);
                }
            }

            $.each(province, function (index, p) {
                var option = "<option value='"   p._id   "'>"   p._areaname   "</option>";
                $("#selProvince").append(option);
            });

            $("#selProvince").change(function () {
                var selValue = $(this).val();
                $("#selCity option:gt(0)").remove();

                $.each(city, function (index, p) {
                    if (p._parentid == selValue) {
                        var option = "<option value='"   p._id   "'>"   p._areaname   "</option>";
                        $("#selCity").append(option);
                    }
                });
            });

            $("#selCity").change(function () {
                var selValue = $(this).val();
                $("#selDistrict option:gt(0)").remove();

                $.each(district, function (index, p) {
                    if (p._parentid == selValue) {
                        var option = "<option value='"   p._id   "'>"   p._areaname   "</option>";
                        $("#selDistrict").append(option);
                    }
                });
            });
        });

    </script>
</head>
<body>
    <select id="selProvince">
        <option value="0">--请选择省份--</option>
    </select>
    <select id="selCity">
        <option value="0">--请选择城市--</option>
    </select>
    <select id="selDistrict">
    <option value="0">--请选择区/县--</option>
    </select>
</body>
</html>