.net和javascript 结合 ,生成三级联动无刷新下拉菜单
step1:首先生成一个area.js
1
//国家列表
2
var nation= new Array();
3
nation[0] = new Array('0','1','阿尔巴尼亚');
4
nation[1] = new Array('0','2','阿尔及利亚');
5
nation[2] = new Array('0','3','阿富汗');
6
nation[3] = new Array('0','4','阿根廷');
7
nation[4] = new Array('0','5','阿拉伯联合酋长国');
8
nation[5] = new Array('0','6','阿鲁巴');
9
nation[6] = new Array('0','7','阿曼');
10
nation[7] = new Array('0','8','阿塞拜疆');
11
nation[8] = new Array('0','9','埃及');
12
nation[9] = new Array('0','10','埃塞俄比亚');
13
nation[10] = new Array('0','11','爱尔兰');
14
nation[11] = new Array('0','12','爱沙尼亚');
15
nation[12] = new Array('0','13','安道尔');
16
nation[13] = new Array('0','14','安哥拉');
17
nation[14] = new Array('0','15','安圭拉岛');
18
nation[15] = new Array('0','16','安提瓜和巴布达');
19
nation[16] = new Array('0','17','奥地利');
20
nation[17] = new Array('0','18','澳大利亚');
21
nation[18] = new Array('0','19','澳门特别行政区');
22
nation[19] = new Array('0','20','巴巴多斯');
23
nation[20] = new Array('0','21','巴布亚新几内亚');
24
nation[21] = new Array('0','22','巴哈马');
25
nation[22] = new Array('0','23','巴基斯坦');
26
nation[23] = new Array('0','24','巴拉圭');
27
nation[24] = new Array('0','25','巴林');
28
nation[25] = new Array('0','26','巴拿马');
29
nation[26] = new Array('0','27','巴西');
30
nation[27] = new Array('0','28','白俄罗斯');
31
nation[28] = new Array('0','29','百慕大群岛');
32
nation[29] = new Array('0','30','保加利亚');
33
nation[30] = new Array('0','31','北马里亚纳群岛');
34
nation[31] = new Array('0','32','贝宁');
35
nation[32] = new Array('0','33','比利时');
36
nation[33] = new Array('0','34','冰岛');
37
nation[34] = new Array('0','35','波多黎各');
38
nation[35] = new Array('0','36','波兰');
39
nation[36] = new Array('0','37','波斯尼亚和黑塞哥维那');
40
nation[37] = new Array('0','38','玻利维亚');
41
nation[38] = new Array('0','39','伯利兹');
42
nation[39] = new Array('0','40','博茨瓦纳');
43
nation[40] = new Array('0','41','不丹');
44
45
46
47
//省份列表
48
var province = new Array();
49
province[0] = new Array('236','238','安徽');
50
province[1] = new Array('236','2948','澳门');
51
province[2] = new Array('236','239','北京');
52
province[3] = new Array('236','241','福建');
53
province[4] = new Array('236','242','甘肃');
54
province[5] = new Array('236','243','广东');
55
province[6] = new Array('236','244','广西');
56
province[7] = new Array('236','245','贵州');
57
province[8] = new Array('236','246','海南');
58
province[9] = new Array('236','247','河北');
59
province[10] = new Array('236','248','河南');
60
province[11] = new Array('236','249','黑龙江');
61
province[12] = new Array('236','250','湖北');
62
province[13] = new Array('236','251','湖南');
63
province[14] = new Array('236','252','吉林');
64
province[15] = new Array('236','253','江苏');
65
province[16] = new Array('236','254','江西');
66
province[17] = new Array('236','255','辽宁');
67
province[18] = new Array('236','256','内蒙古');
68
province[19] = new Array('236','257','宁夏');
69
province[20] = new Array('236','258','青海');
70
province[21] = new Array('236','259','山东');
71
province[22] = new Array('236','260','山西');
72
province[23] = new Array('236','261','陕西');
73
province[24] = new Array('236','262','上海');
74
province[25] = new Array('236','263','四川');
75
province[26] = new Array('236','2949','台湾');
76
province[27] = new Array('236','264','天津');
77
province[28] = new Array('236','265','西藏');
78
province[29] = new Array('236','2947','香港');
79
province[30] = new Array('236','266','新疆');
80
province[31] = new Array('236','267','云南');
81
province[32] = new Array('236','268','浙江');
82
province[33] = new Array('236','240','重庆');
83
84
85
86
87
88
//市级列表
89
var city= new Array();
90
city[0] = new Array('251','1645','永州','425000','0746');
91
city[1] = new Array('263','2468','广元','628000','0839');
92
city[2] = new Array('240','2946','万州区','401420','023');
93
city[3] = new Array('2947','2950','湾仔区','','00852');
94
city[4] = new Array('2947','2951','东区','','00852');
95
city[5] = new Array('2947','2952','中西区','','00852');
96
city[6] = new Array('2947','2953','南 区','','00852');
97
city[7] = new Array('2947','2954','北 区','','00852');
98
city[8] = new Array('2947','2955','九龙城区','','00852');
99
city[9] = new Array('2949','2956','台北市','222','2');
100
city[10] = new Array('2949','2957','高雄市','800','7');
101
city[11] = new Array('2949','2958','台中市','400','42');
102
city[12] = new Array('2949','2959','台南市','700','62');
103
city[13] = new Array('2949','2960','基隆市','200','32');
104
city[14] = new Array('2949','2961','新竹市','300','35');
105
city[15] = new Array('2949','2962','嘉义市','600','52');
106
city[16] = new Array('2949','2963','台北县','222','2');
107
city[17] = new Array('2949','2964','宜兰县','','');
108
city[18] = new Array('2949','2965','桃园县','','');
109
city[19] = new Array('2949','2966','新竹县','300','35');
110
city[20] = new Array('2949','2967','苗栗县','','');
111
city[21] = new Array('2949','2968','台中县','400','42');
112
city[22] = new Array('2949','2975','高雄县','800','7');
113
city[23] = new Array('2949','2970','彰化县','','');
114
city[24] = new Array('2949','2971','南投县','','');
115
city[25] = new Array('2949','2972','云林县','','');
116
city[26] = new Array('2949','2973','嘉义县','600','52');
117
city[27] = new Array('2949','2974','台南县','700','62');
118
city[28] = new Array('2949','2976','屏东县','','');
119
city[29] = new Array('2949','2977','台东县','','');
120
city[30] = new Array('2949','2978','花莲县','','');
121
city[31] = new Array('2949','2979','澎湖县','','');
122
city[32] = new Array('2947','2982','观塘区','','00852');
123
city[33] = new Array('2947','2983','油尖旺区','','00852');
124
city[34] = new Array('2947','2984','深水埗区','','00852');
125
city[35] = new Array('2947','2985','葵青区','','00852');
126
city[36] = new Array('2947','2986','沙田区','','00852');
127
city[37] = new Array('2947','2987','黄大仙区','','00852');
128
city[38] = new Array('2947','2988','荃湾区','','00852');
129
city[39] = new Array('2947','2989','元朗区','','00852');
130
city[40] = new Array('2947','2990','屯门区','','00852');
131
city[41] = new Array('2947','2991','离岛区','','00852');
132
city[42] = new Array('2947','2992','西贡区','','00852');
133
city[43] = new Array('2947','2993','大埔区','','00852');
134
city[44] = new Array('2948','2994','澳门半岛','','00853');
135
city[45] = new Array('2948','2995','凼仔','','00853');
136
city[46] = new Array('2948','2996','路环','','00853');
137
city[47] = new Array('238','272','安庆','246000','0556');
138
city[48] = new Array('238','273','蚌埠','233000','0552');
139
city[49] = new Array('238','274','巢湖','238000','0565');
140
city[50] = new Array('238','275','池州','','');
141
city[51] = new Array('238','276','滁州','239000','0550');
142
city[52] = new Array('238','277','阜阳','236000','0558');
143
city[53] = new Array('238','278','合肥','230000','0551');
144
city[54] = new Array('238','279','淮北','235000','0561');
145
city[55] = new Array('238','280','淮南','232000','0554');
146
city[56] = new Array('238','281','黄山','245000','0559');
147
city[57] = new Array('238','282','六安','237000','0564');
148
city[58] = new Array('238','283','马鞍山','243000','0555');
149
city[59] = new Array('238','284','宿州','234000','0557');
150
city[60] = new Array('238','285','铜陵','244000','0562');
151
city[61] = new Array('238','286','芜湖','241000','0553');
152
city[62] = new Array('238','287','宣城','242000','0563');
153
city[63] = new Array('238','288','亳州','236802','');
154
city[64] = new Array('239','289','东城区','100007','010');
155
city[65] = new Array('241','290','福州','350000','0591');
156
city[66] = new Array('241','291','龙岩','364000','0597');
157
city[67] = new Array('241','292','南平','353000','0599');
158
city[68] = new Array('241','293','宁德','352100','0593');
159
city[69] = new Array('241','294','莆田','351100','0594');
160
city[70] = new Array('241','295','泉州','362000','0595');
161
city[71] = new Array('241','296','三明','365000','0598');
162
city[72] = new Array('241','297','厦门','361000','0592');
163
city[73] = new Array('241','298','漳州','363000','0596');
164
city[74] = new Array('242','299','白银','730900','0943');
165
city[75] = new Array('242','300','定西','743000','0932');
166
city[76] = new Array('242','301','甘南藏族自治州','747000','09411');
167
city[77] = new Array('242','302','嘉峪关','735100','0937');
168
city[78] = new Array('242','303','金昌','733000','0935');
169
city[79] = new Array('242','304','酒泉','735000','0937');
170
city[80] = new Array('242','305','兰州','730000','0931');
171
city[81] = new Array('242','306','临夏回族自治州','731800','09401');
172
city[82] = new Array('242','307','陇南','','');
173
city[83] = new Array('242','308','平凉','744000','0943');
174
city[84] = new Array('242','309','庆阳','745100','09441');
175
city[85] = new Array('242','310','天水','741000','0938');
176
city[86] = new Array('242','311','武威','733000','');
177
city[87] = new Array('242','312','张掖','734000','0936');
178
city[88] = new Array('243','313','潮州','515600','0768');
179
city[89] = new Array('243','314','东莞','511700','0769');
180
city[90] = new Array('243','315','佛山','528000','0757');
181
city[91] = new Array('243','316','广州','510000','020');
182
city[92] = new Array('243','317','河源','517000','0762');
183
city[93] = new Array('243','318','惠州','516000','0752');
184
city[94] = new Array('243','319','江门','529000','0750');
185
city[95] = new Array('243','320','揭阳','515500','0663');
186
city[96] = new Array('243','321','茂名','525000','0668');
187
city[97] = new Array('243','322','梅州','514000','0753');
188
city[98] = new Array('243','323','清远','511500','0763');
189
city[99] = new Array('243','324','汕头','515000','0754');
190
city[100] = new Array('243','325','汕尾','516600','0660');
191
192
193
194
/*更多城市 ,不一一列出*/
195
196
197
198
199
var PostCode,TelCode;
200
PostCode='';
201
TelCode='';
202
function CreateNationID(targForm){//生成国家级分类
203
var targ=targForm.NationID;
204
targ.length = 0;
205
targ.options[targ.length] = new Option('选择国家','0');
206
for(i=0; i<nation.length; i++){
207
targ.options[targ.length] = new Option(nation[i][2], nation[i][1]);
208
}
209
targ.selectedIndex=236 //选定中国
210
}
211
212
function CreateProvinceID(targForm){//生成省级分类 targForm为目标表单
213
var parent=targForm.NationID;
214
var subfield=targForm.ProvinceID;
215
var classid;
216
if(parent.length>0)
217
classid=parent.options[parent.selectedIndex].value
218
else
219
classid=parent.value;
220
subfield.length = 0;
221
subfield.options[subfield.length] = new Option('选择省份','0');
222
for (i=0; i < province.length; i++){
223
if (province[i][0] == classid){
224
subfield.options[subfield.length] = new Option(province[i][2], province[i][1]);
225
}
226
}
227
}
228
229
function CreateCityID(targForm){//生成市级分类
230
var subfield=targForm.CityID;
231
var classid=targForm.ProvinceID.options[targForm.ProvinceID.selectedIndex].value;
232
subfield.length = 0;
233
subfield.options[subfield.length] = new Option('选择城市','0');
234
for (i=0; i < city.length; i++){
235
if (city[i][0] == classid){
236
subfield.options[subfield.length] = new Option(city[i][2], city[i][1]);
237
}
238
}
239
}
240
241
function CreateCountyID(targForm){//生成区县级分类
242
var subfield=targForm.CountyID;
243
var classid=targForm.CityID.options[targForm.CityID.selectedIndex].value;
244
subfield.length = 0;
245
subfield.options[subfield.length] = new Option('选择区县','0');
246
for (i=0; i < county.length; i++){
247
if (county[i][0] == classid){
248
subfield.options[subfield.length] = new Option(county[i][2], county[i][1]);
249
}
250
}
251
}
252
253
254
function CreatePostTelCode(targForm) {//生成邮编、区号
255
var classid=targForm.CityID.options[targForm.CityID.selectedIndex].value;
256
for (i=0; i < city.length; i++){
257
if (city[i][1] == classid){
258
PostCode=city[i][3];
259
TelCode=city[i][4];
260
break;
261
}
262
}
263
}
//国家列表2
var nation= new Array();3
nation[0] = new Array('0','1','阿尔巴尼亚');4
nation[1] = new Array('0','2','阿尔及利亚');5
nation[2] = new Array('0','3','阿富汗');6
nation[3] = new Array('0','4','阿根廷');7
nation[4] = new Array('0','5','阿拉伯联合酋长国');8
nation[5] = new Array('0','6','阿鲁巴');9
nation[6] = new Array('0','7','阿曼');10
nation[7] = new Array('0','8','阿塞拜疆');11
nation[8] = new Array('0','9','埃及');12
nation[9] = new Array('0','10','埃塞俄比亚');13
nation[10] = new Array('0','11','爱尔兰');14
nation[11] = new Array('0','12','爱沙尼亚');15
nation[12] = new Array('0','13','安道尔');16
nation[13] = new Array('0','14','安哥拉');17
nation[14] = new Array('0','15','安圭拉岛');18
nation[15] = new Array('0','16','安提瓜和巴布达');19
nation[16] = new Array('0','17','奥地利');20
nation[17] = new Array('0','18','澳大利亚');21
nation[18] = new Array('0','19','澳门特别行政区');22
nation[19] = new Array('0','20','巴巴多斯');23
nation[20] = new Array('0','21','巴布亚新几内亚');24
nation[21] = new Array('0','22','巴哈马');25
nation[22] = new Array('0','23','巴基斯坦');26
nation[23] = new Array('0','24','巴拉圭');27
nation[24] = new Array('0','25','巴林');28
nation[25] = new Array('0','26','巴拿马');29
nation[26] = new Array('0','27','巴西');30
nation[27] = new Array('0','28','白俄罗斯');31
nation[28] = new Array('0','29','百慕大群岛');32
nation[29] = new Array('0','30','保加利亚');33
nation[30] = new Array('0','31','北马里亚纳群岛');34
nation[31] = new Array('0','32','贝宁');35
nation[32] = new Array('0','33','比利时');36
nation[33] = new Array('0','34','冰岛');37
nation[34] = new Array('0','35','波多黎各');38
nation[35] = new Array('0','36','波兰');39
nation[36] = new Array('0','37','波斯尼亚和黑塞哥维那');40
nation[37] = new Array('0','38','玻利维亚');41
nation[38] = new Array('0','39','伯利兹');42
nation[39] = new Array('0','40','博茨瓦纳');43
nation[40] = new Array('0','41','不丹');44

45

46

47
//省份列表48
var province = new Array();49
province[0] = new Array('236','238','安徽');50
province[1] = new Array('236','2948','澳门');51
province[2] = new Array('236','239','北京');52
province[3] = new Array('236','241','福建');53
province[4] = new Array('236','242','甘肃');54
province[5] = new Array('236','243','广东');55
province[6] = new Array('236','244','广西');56
province[7] = new Array('236','245','贵州');57
province[8] = new Array('236','246','海南');58
province[9] = new Array('236','247','河北');59
province[10] = new Array('236','248','河南');60
province[11] = new Array('236','249','黑龙江');61
province[12] = new Array('236','250','湖北');62
province[13] = new Array('236','251','湖南');63
province[14] = new Array('236','252','吉林');64
province[15] = new Array('236','253','江苏');65
province[16] = new Array('236','254','江西');66
province[17] = new Array('236','255','辽宁');67
province[18] = new Array('236','256','内蒙古');68
province[19] = new Array('236','257','宁夏');69
province[20] = new Array('236','258','青海');70
province[21] = new Array('236','259','山东');71
province[22] = new Array('236','260','山西');72
province[23] = new Array('236','261','陕西');73
province[24] = new Array('236','262','上海');74
province[25] = new Array('236','263','四川');75
province[26] = new Array('236','2949','台湾');76
province[27] = new Array('236','264','天津');77
province[28] = new Array('236','265','西藏');78
province[29] = new Array('236','2947','香港');79
province[30] = new Array('236','266','新疆');80
province[31] = new Array('236','267','云南');81
province[32] = new Array('236','268','浙江');82
province[33] = new Array('236','240','重庆');83

84

85

86

87

88
//市级列表89
var city= new Array();90
city[0] = new Array('251','1645','永州','425000','0746');91
city[1] = new Array('263','2468','广元','628000','0839');92
city[2] = new Array('240','2946','万州区','401420','023');93
city[3] = new Array('2947','2950','湾仔区','','00852');94
city[4] = new Array('2947','2951','东区','','00852');95
city[5] = new Array('2947','2952','中西区','','00852');96
city[6] = new Array('2947','2953','南 区','','00852');97
city[7] = new Array('2947','2954','北 区','','00852');98
city[8] = new Array('2947','2955','九龙城区','','00852');99
city[9] = new Array('2949','2956','台北市','222','2');100
city[10] = new Array('2949','2957','高雄市','800','7');101
city[11] = new Array('2949','2958','台中市','400','42');102
city[12] = new Array('2949','2959','台南市','700','62');103
city[13] = new Array('2949','2960','基隆市','200','32');104
city[14] = new Array('2949','2961','新竹市','300','35');105
city[15] = new Array('2949','2962','嘉义市','600','52');106
city[16] = new Array('2949','2963','台北县','222','2');107
city[17] = new Array('2949','2964','宜兰县','','');108
city[18] = new Array('2949','2965','桃园县','','');109
city[19] = new Array('2949','2966','新竹县','300','35');110
city[20] = new Array('2949','2967','苗栗县','','');111
city[21] = new Array('2949','2968','台中县','400','42');112
city[22] = new Array('2949','2975','高雄县','800','7');113
city[23] = new Array('2949','2970','彰化县','','');114
city[24] = new Array('2949','2971','南投县','','');115
city[25] = new Array('2949','2972','云林县','','');116
city[26] = new Array('2949','2973','嘉义县','600','52');117
city[27] = new Array('2949','2974','台南县','700','62');118
city[28] = new Array('2949','2976','屏东县','','');119
city[29] = new Array('2949','2977','台东县','','');120
city[30] = new Array('2949','2978','花莲县','','');121
city[31] = new Array('2949','2979','澎湖县','','');122
city[32] = new Array('2947','2982','观塘区','','00852');123
city[33] = new Array('2947','2983','油尖旺区','','00852');124
city[34] = new Array('2947','2984','深水埗区','','00852');125
city[35] = new Array('2947','2985','葵青区','','00852');126
city[36] = new Array('2947','2986','沙田区','','00852');127
city[37] = new Array('2947','2987','黄大仙区','','00852');128
city[38] = new Array('2947','2988','荃湾区','','00852');129
city[39] = new Array('2947','2989','元朗区','','00852');130
city[40] = new Array('2947','2990','屯门区','','00852');131
city[41] = new Array('2947','2991','离岛区','','00852');132
city[42] = new Array('2947','2992','西贡区','','00852');133
city[43] = new Array('2947','2993','大埔区','','00852');134
city[44] = new Array('2948','2994','澳门半岛','','00853');135
city[45] = new Array('2948','2995','凼仔','','00853');136
city[46] = new Array('2948','2996','路环','','00853');137
city[47] = new Array('238','272','安庆','246000','0556');138
city[48] = new Array('238','273','蚌埠','233000','0552');139
city[49] = new Array('238','274','巢湖','238000','0565');140
city[50] = new Array('238','275','池州','','');141
city[51] = new Array('238','276','滁州','239000','0550');142
city[52] = new Array('238','277','阜阳','236000','0558');143
city[53] = new Array('238','278','合肥','230000','0551');144
city[54] = new Array('238','279','淮北','235000','0561');145
city[55] = new Array('238','280','淮南','232000','0554');146
city[56] = new Array('238','281','黄山','245000','0559');147
city[57] = new Array('238','282','六安','237000','0564');148
city[58] = new Array('238','283','马鞍山','243000','0555');149
city[59] = new Array('238','284','宿州','234000','0557');150
city[60] = new Array('238','285','铜陵','244000','0562');151
city[61] = new Array('238','286','芜湖','241000','0553');152
city[62] = new Array('238','287','宣城','242000','0563');153
city[63] = new Array('238','288','亳州','236802','');154
city[64] = new Array('239','289','东城区','100007','010');155
city[65] = new Array('241','290','福州','350000','0591');156
city[66] = new Array('241','291','龙岩','364000','0597');157
city[67] = new Array('241','292','南平','353000','0599');158
city[68] = new Array('241','293','宁德','352100','0593');159
city[69] = new Array('241','294','莆田','351100','0594');160
city[70] = new Array('241','295','泉州','362000','0595');161
city[71] = new Array('241','296','三明','365000','0598');162
city[72] = new Array('241','297','厦门','361000','0592');163
city[73] = new Array('241','298','漳州','363000','0596');164
city[74] = new Array('242','299','白银','730900','0943');165
city[75] = new Array('242','300','定西','743000','0932');166
city[76] = new Array('242','301','甘南藏族自治州','747000','09411');167
city[77] = new Array('242','302','嘉峪关','735100','0937');168
city[78] = new Array('242','303','金昌','733000','0935');169
city[79] = new Array('242','304','酒泉','735000','0937');170
city[80] = new Array('242','305','兰州','730000','0931');171
city[81] = new Array('242','306','临夏回族自治州','731800','09401');172
city[82] = new Array('242','307','陇南','','');173
city[83] = new Array('242','308','平凉','744000','0943');174
city[84] = new Array('242','309','庆阳','745100','09441');175
city[85] = new Array('242','310','天水','741000','0938');176
city[86] = new Array('242','311','武威','733000','');177
city[87] = new Array('242','312','张掖','734000','0936');178
city[88] = new Array('243','313','潮州','515600','0768');179
city[89] = new Array('243','314','东莞','511700','0769');180
city[90] = new Array('243','315','佛山','528000','0757');181
city[91] = new Array('243','316','广州','510000','020');182
city[92] = new Array('243','317','河源','517000','0762');183
city[93] = new Array('243','318','惠州','516000','0752');184
city[94] = new Array('243','319','江门','529000','0750');185
city[95] = new Array('243','320','揭阳','515500','0663');186
city[96] = new Array('243','321','茂名','525000','0668');187
city[97] = new Array('243','322','梅州','514000','0753');188
city[98] = new Array('243','323','清远','511500','0763');189
city[99] = new Array('243','324','汕头','515000','0754');190
city[100] = new Array('243','325','汕尾','516600','0660');191

192

193

194
/*更多城市 ,不一一列出*/195

196

197

198

199
var PostCode,TelCode;200
PostCode='';201
TelCode='';202
function CreateNationID(targForm){//生成国家级分类 203
var targ=targForm.NationID;204
targ.length = 0;205
targ.options[targ.length] = new Option('选择国家','0');206
for(i=0; i<nation.length; i++){207
targ.options[targ.length] = new Option(nation[i][2], nation[i][1]);208
}209
targ.selectedIndex=236 //选定中国210
}211

212
function CreateProvinceID(targForm){//生成省级分类 targForm为目标表单213
var parent=targForm.NationID;214
var subfield=targForm.ProvinceID;215
var classid;216
if(parent.length>0)217
classid=parent.options[parent.selectedIndex].value218
else219
classid=parent.value;220
subfield.length = 0;221
subfield.options[subfield.length] = new Option('选择省份','0');222
for (i=0; i < province.length; i++){223
if (province[i][0] == classid){224
subfield.options[subfield.length] = new Option(province[i][2], province[i][1]);225
}226
}227
}228

229
function CreateCityID(targForm){//生成市级分类230
var subfield=targForm.CityID;231
var classid=targForm.ProvinceID.options[targForm.ProvinceID.selectedIndex].value;232
subfield.length = 0;233
subfield.options[subfield.length] = new Option('选择城市','0');234
for (i=0; i < city.length; i++){235
if (city[i][0] == classid){236
subfield.options[subfield.length] = new Option(city[i][2], city[i][1]);237
}238
}239
}240

241
function CreateCountyID(targForm){//生成区县级分类242
var subfield=targForm.CountyID;243
var classid=targForm.CityID.options[targForm.CityID.selectedIndex].value;244
subfield.length = 0;245
subfield.options[subfield.length] = new Option('选择区县','0');246
for (i=0; i < county.length; i++){247
if (county[i][0] == classid){248
subfield.options[subfield.length] = new Option(county[i][2], county[i][1]);249
}250
}251
}252

253

254
function CreatePostTelCode(targForm) {//生成邮编、区号255
var classid=targForm.CityID.options[targForm.CityID.selectedIndex].value; 256
for (i=0; i < city.length; i++){257
if (city[i][1] == classid){258
PostCode=city[i][3];259
TelCode=city[i][4];260
break;261
}262
}263
}ClassChange.js
function CreateRootID(targForm){//生成省级分类 targForm为目标表单
var parent=targForm.NationID;
var subfield=targForm.RootID;
var classid;
if(parent.length>0)
classid=parent.options[parent.selectedIndex].value
else
classid=parent.value;
subfield.length = 0;
subfield.options[subfield.length] = new Option('选择省份','0');
for (i=0; i < province.length; i++){
if (Root[i][0] == classid){
subfield.options[subfield.length] = new Option(Root[i][2], Root[i][1]);
}
}
}
function CreateClassID(targForm){//生成市级分类
var subfield=targForm.ClassID;
var classid=targForm.RootID.options[targForm.RootID.selectedIndex].value;
subfield.length = 0;
subfield.options[subfield.length] = new Option('选择城市','0');
for (i=0; i < Class.length; i++){
if (Class[i][0] == classid){
subfield.options[subfield.length] = new Option(Class[i][2], Class[i][1]);
}
}
}
function CreateKindID(targForm){//生成区县级分类
var subfield=targForm.KindID;
var classid=targForm.ClassID.options[targForm.ClassID.selectedIndex].value;
subfield.length = 0;
subfield.options[subfield.length] = new Option('选择区县','0');
for (i=0; i < Kind.length; i++){
if (Kind[i][0] == classid){
subfield.options[subfield.length] = new Option(Kind[i][2], Kind[i][1]);
}
}
}

classFunction.js
function CreateRootID(targForm,sType){//生成一级分类 targForm为目标表单
var targ=targForm.RootID;
targ.length = 0;
targ.options[targ.length] = new Option('一级分类','');
for(i=0; i<Root.length; i++){
if (Root[i][0] == sType){
targ.options[targ.length] = new Option(Root[i][2], Root[i][1]);
}
}
}
function CreateClassID(targForm){//生成二级分类 targForm为目标表单
var parent=targForm.RootID;
var subfield=targForm.ClassID;
var classid;
classid=parent.options[parent.selectedIndex].value;
subfield.length = 0;
subfield.options[subfield.length] = new Option('二级分类','');
for (i=0; i < Class.length; i++){
if (Class[i][0] == classid){
subfield.options[subfield.length] = new Option(Class[i][2], Class[i][1]);
}
}
}
function CreateKindID(targForm){//生成三级分类 targForm为目标表单
var parent=targForm.ClassID;
var subfield=targForm.KindID;
var classid;
classid=parent.options[parent.selectedIndex].value;
subfield.length = 0;
subfield.options[subfield.length] = new Option('三级分类','');
for (i=0; i < Kind.length; i++){
if (Kind[i][0] == classid){
subfield.options[subfield.length] = new Option(Kind[i][2], Kind[i][1]);
}
}
}然后就是调用这几个js文件了
在default.aspx页面中
<%@ Page language="c#" Codebehind="index.aspx.cs" AutoEventWireup="false" Inherits="CnTvS.Admin.Product.index1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>index</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script src="/CnTvS/Js/classFunction.js" type="text/javascript"></script>
<script src="CreateJs.js" type="text/javascript"></script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="composeform" method="post" runat="server">
<table class="table" id="Table2" cellSpacing="1" cellPadding="5" width="100%" border="0">
<TBODY>
<tr class="xingmu">
<td align="center" colSpan="4">搜索、添加</td>
</tr>
<tr class="back">
<td style="WIDTH: 92px" align="right">分类:</td>
<td style="WIDTH: 279px">
<select name="RootID" id="RootID" onchange="CreateClassID(this.form);this.form.KindID.length=1;">
<option value="" selected>一级分类</option>
</select>
<select name="ClassID" id="ClassID" onchange="CreateKindID(this.form);">
<option value="" selected>二级分类</option>
</select>
<select name="KindID" id="KindID">
<option value="" selected>三级分类</option>
</select>
</td>
</tr>
</TBODY>
</table>
</form>
<script type="text/javascript">
<!--
tf=document.composeform;
CreateRootID(tf,1);
CreateClassID(tf);
CreateKindID(tf);
//-->
</script>
</form>
</body>
</HTML>
注意这里用的是由html控件转到的服务器端控件 这样用控件的好处是可以比较灵活的调用js,又能在后台文件中获得值
在cs文件中必须要使用request来得到值
前面大家都说有问题,但是这个东西一直是我们用的 ,所以也没有怎么仔细看,昨天看了下,才发现确实有点问题
修改版本 http://www.cnblogs.com/Caceolod/articles/921974.html



浙公网安备 33010602011771号