省市區信息的CheckBox選擇

`$.getJSON("../Common/WebCity.ashx", { level: 0 }, function (data) { for (var i = 0; i < data.length; i++) { $("#areas").append($("<option value='" + data[i].id + "'>" + data[i].text + "</option>")); } });app

$("#areas").change(function () {
            if ($("#areas").val() != "-1" && $("#areas").val() != "0") {
                $.getJSON("../Common/WebCity.ashx", { level: 1, pid: $("#areas").val() }, function(data) {
                    $("#province").empty();
                    for (var i = 0; i < data.length; i++) {
                        $("#province").append($("<option value='" + data[i].id + "'>" + data[i].text + "</option>"));
                    }
                    $("#province").change();
                });
            } else {
                $("#province").empty();
                $("#city").empty();
            }
        });

        $("#province").change(function () {
            $("#city").empty();
            $.getJSON("../Common/WebCity.ashx", { level: 2, pid: $("#province").val() }, function (data) {
                for (var i = 0; i < data.length; i++) {
                    $("#city").append($("<div><input type='checkbox' value='" + data[i].id + "' name='selCity'/>" + data[i].text + "</div>"));
                }
                $("#selectAll").attr("checked", "");
                loadChecked();
            });
        });

        $("input[id='selectAll']").click(function () {
            var isChecked = this.checked;
            $(this).parent().parent().find(".select input").each(function (i) {
                this.checked = isChecked;
                if (isChecked && $("#divSelCity #city" + this.value).length == 0) {
                    $("#divSelCity").append($("<div id='city" + this.value + "'><input type='checkbox' id='chkCity" + this.value + "' name='chkCity' checked='checked' value='" + this.value + "'>" + $(this).parent().text() + "</div>"));
                }
                else {
                    $("#city" + this.value).remove();
                }
            });
        });`
相關文章
相關標籤/搜索