CB2-20200827ONU\Administrator
2021-09-22 4d584101e46ff34b2694e88af706b9b2e92364bc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
城市区域JS
吴辉
20130417
 
*/
 
/*
1.城市区域
//页面使用
<div class="popupMenu" id="PCACCommon"></div>
<script type="text/javascript">
PCAC('<%=Province %>', '<%=City %>', '<%=County %>',"Name");//城市数据存名称用Name,存编号则空字符
</script>
 
//后台使用
//声明
public string Province = ""; //接收值 Request["selectProvince"].ToString2();
public string City = "";//接收值 Request["selectCity"].ToString2();
public string County = "";//接收值 Request["selectCounty"].ToString2();
 
//赋值
Province = model.Province.ToString2();
City= model.City.ToString2();
County = model.County.ToString2();
    
//接收
model.Province = Request["selectProvince"].ToString2();
model.City = Request["selectCity"].ToString2();
model.County = Request["selectCounty"].ToString2();
 
参数:省,市,区,数据类型(名称用Name,存编号则空字符)
*/
 
function PCACProvince(old_province, date_type) {
    var PcacHtml = "<select id='selectProvince' name='selectProvince'  keepDefaultStyle='true' style='width:76px;'><option value=''>请选择</option></select>";
    $("#PCACCommon").html(PcacHtml);
    PCACData(old_province, "", "", date_type);
}
 
function PCACCity(old_province, old_city, date_type) {
    var PcacHtml = "<select id='selectProvince' name='selectProvince' keepDefaultStyle='true' style='width:76px;'><option value=''>请选择</option></select>  <select id='selectCity' name='selectCity'  keepDefaultStyle='true'  style='width:76px;'><option value=''>请选择</option></select>";
    $("#PCACCommon").html(PcacHtml);
    PCACData(old_province, old_city, "", date_type);
}
 
function PCACCounty(old_province, old_city, old_county, date_type) {
    var PcacHtml = "<select id='selectProvince' name='selectProvince'  keepDefaultStyle='true' style='width:76px;'><option value=''>请选择</option></select>  <select id='selectCity' name='selectCity'  keepDefaultStyle='true'  style='width:76px;'><option value=''>请选择</option></select>  <select id='selectCounty' name='selectCounty' keepDefaultStyle='true' style='width:76px;'><option value=''>请选择</option></select>";
    $("#PCACCommon").html(PcacHtml);
    PCACData(old_province, old_city, old_county, date_type);
}
 
function PCAC(old_province, old_city, old_county, date_type) {
    if (arguments.length == 2) {
        PCACProvince(old_province, old_city);
        return;
    } else if (arguments.length == 3) {
        PCACCity(old_province, old_city, old_county);
        return;
    } else if (arguments.length == 4) {
        PCACCounty(old_province, old_city, old_county, date_type);
        return;
    }
}
 
 
function PCACData(old_province, old_city, old_county, date_type) {
    try {
        //加载省
        $.ajax({
            url: "/Pages/common/CommonAjax.aspx",
            type: "POST",
            dataType: "html",
            data: { cityType: "province" },
            global: false,
            cache: false,
            success: function (data) {
                var myobj = null;
                if (data != null && data != "" && data != undefined) {
                    myobj = eval('(' + data + ')');
                }
                var hasProvince = false;
                if (myobj != null && myobj.length > 0) {
                    for (var i = 0; i < myobj.length; i++) {
                        var city_keyid = myobj[i].Keyid;
                        var city_name = myobj[i].Name;
                        var option = "";
                        
                        if (!hasProvince && city_name == old_province) {
                            hasProvince = true;
                        }
                        if (date_type == "Name") {
                            option = "<option value = '" + city_name + "'>" + city_name + "</option>";
                        } else {
                            option = "<option value = '" + city_keyid + "'>" + city_name + "</option>";
                        }
                        $(option).appendTo($("#selectProvince"));
                        $("#selectProvince").attr("class", "fl");
 
                        $("#selectCity").attr("class", "fl ml5px");
 
                        $("#selectCounty").attr("class", "fl ml5px");
                    }
                }
                if (hasProvince) {
                    $("#selectProvince").val(old_province);
                }
                $("#selectProvince").change();
            }
        });
 
        //加载市
        $("#selectProvince").live("change", function () {
            $.ajax({
                url: "/Pages/common/CommonAjax.aspx",
                type: "POST",
                dataType: "html",
                data: { old_province: $("#selectProvince").val(), cityType: "city", date_type: date_type },
                global: false,
                cache: false,
                success: function (data) {
                    $("#selectCity").html("<option value=''>请选择</option>");
                    var myobj = null;
                    if (data != null && data != "" && data != undefined) {
                        myobj = eval('(' + data + ')');
                    }
                    var hasCity = false;
                    if (myobj != null && myobj.length > 0) {
                        for (var i = 0; i < myobj.length; i++) {
                            var city_keyid = myobj[i].Keyid;
                            var city_name = myobj[i].Name;
                            var option = "";
                            if (!hasCity && city_name == old_city) {
                                hasCity = true;
                            }
                            if (date_type == "Name") {
                                option = "<option value = '" + city_name + "'>" + city_name + "</option>";
                            } else {
                                option = "<option value = '" + city_keyid + "'>" + city_name + "</option>";
                            }
                            $(option).appendTo($("#selectCity"));
                            $("#selectProvince").attr("class", "fl");
 
                            var classStr = $("#selectCity").attr("class");
                            $("#selectCity").attr("class", "");
                            $("#selectCity").attr("class", classStr);
 
                            $("#selectCounty").attr("class", "fl ml5px");
                        }
                    }
                    if (hasCity) {
                        $("#selectCity").val(old_city);
                    }
                    $("#selectCity").change();
                    $("#selectCity").attr('isLoaded', true);
                }
            });
        });
        //加载区县
        $("#selectCity").live("change", function () {
            if (window.citychangecallback && $("#selectCity").attr('isLoaded') == 'true') window.citychangecallback();
            $.ajax({
                url: "/Pages/common/CommonAjax.aspx",
                type: "POST",
                dataType: "html",
                data: { old_city: $("#selectCity").val(), cityType: "county", date_type: date_type },
                global: false,
                cache: false,
                success: function (data) {
                    $("#selectCounty").html("<option value=''>请选择</option>");
                    var myobj = null;
                    if (data != null && data != "" && data != undefined) {
                        myobj = eval('(' + data + ')');
                    }
                    var hasCounty = false;
                    if (myobj != null && myobj.length > 0) {
                        for (var i = 0; i < myobj.length; i++) {
                            var city_keyid = myobj[i].Keyid;
                            var city_name = myobj[i].Name;
                            var option = "";
                            if (!hasCounty && city_name == old_county) {
                                hasCounty = true;
                            }
                            if (date_type == "Name") {
                                option = "<option value = '" + city_name + "'>" + city_name + "</option>";
                            } else {
                                option = "<option value = '" + city_keyid + "'>" + city_name + "</option>";
                            }
                            $(option).appendTo($("#selectCounty"));
                            $("#selectProvince").attr("class", "fl");
 
                            var classStr = $("#selectCity").attr("class");
                            $("#selectCity").attr("class", "");
                            $("#selectCity").attr("class", classStr);
 
                            $("#selectCounty").attr("class", "fl ml5px");
                        }
                        if (hasCounty) {
                            $("#selectCounty").val(old_county);
                        }
                        //$("#selectCounty").change();
                        $("#selectCounty").attr('isLoaded', true);
                    }
                }
            });
        });
        $("#selectCounty").live("change", function () {
            if (window.citychangecallback && $("#selectCounty").attr('isLoaded') == 'true') window.citychangecallback();
        });
    } catch (e) {
 
    }
 
}
 
function GetProvince(date_type) {
    if (date_type == "Name") {
        return $("#selectProvince").find("option:selected").text();
    } else {
        return $("#selectProvince").val();
    }
}
 
function GetCity(date_type) {
    if (date_type == "Name") {
        return $("#selectCity").find("option:selected").text();
    } else {
        return $("#selectCity").val();
    }
}
 
function GetCounty(date_type) {
    if (date_type == "Name") {
        return $("#selectCounty").find("option:selected").text();
    } else {
        return $("#selectCounty").val();
    }
}