随笔 - 418  文章 - 3  评论 - 331  阅读 - 120万

jquery select选中表单特效三级联动

好久没发帖了,今天发一个jquery select的表单三级联动,希望能对有需要的朋友有点帮助。

js代码,当然还要加上jquery的包,应该都有的,这里就不发了。

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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<script type="text/javascript">
var threeSelectData={
     
    "选择频道":{
        val:"",
        items:{
            "二级子菜单":{
                val:"",
                items:{
                    "三级子菜单":""
                }
            }
        }
    },
     
    "jquery特效":{
        val:"jquery",
        items:{
            "jquery图片特效":{
                val:"jqpic",
                items:{
                    "jquery图片切换":"jqpic-01",
                    "jquery幻灯片":"jqpic-02",
                    "jquery图片滚动":"jqpic-03",
                    "jquery图片放大":"jqpic-04",
                    "jquery广告":"jqpic-05",
                    "jquery图片其它":"jqpic-06"
                }
            },
             
            "jquery导航菜单":{
                val:"jqnav",
                items:{
                    "jquery动画菜单":"jqnav-01",
                    "jquery下拉菜单":"jqnav-02",
                    "jquery手风琴菜单":"jqnav-03",
                    "jquery导航其它":"jqnav-04"
                }
            },
             
            "jquery选项卡特效":{
                val:"jqtab",
                items:{
                    "jquery选项卡切换":"jqtab-01",
                    "jquery滑动选项卡":"jqtab-02"
                }
            },
             
            "jquery文字特效":{
                val:"jqfont",
                items:{
                    "jquery文字滚动":"jqfont-01",
                    "jquery文字切换":"jqfont-02",
                    "jquery文字其它":"jqfont-03"
                }
            },
             
            "jquery表单特效":{
                val:"jqform",
                items:{
                    "jquery表单验证":"jqform-01",
                    "jquery表单美化":"jqform-02",
                    "jquery表单其它":"jqform-03"
                }
            },
             
            "jquery滚动条美化":{
                val:"jqscroll",
                items:{}
            },
             
            "jquery评分,进度条,日期时间":{
                val:"jqrate",
                items:{}
            },
             
            "jquery提示框,弹出层,浮动层":{
                val:"jqdiv",
                items:{}
            },
             
            "jquery其它特效":{
                val:"jqother",
                items:{}
            }
             
        }
    },
     
    "js特效":{
        val:"js",
        items:{
             
            "js图片特效":{
                val:"jspic",
                items:{
                    "js图片切换":"jspic-01",
                    "js幻灯片":"jspic-02",
                    "js图片滚动":"jspic-03",
                    "js图片放大":"jspic-04",
                    "js广告":"jspic05",
                    "js图片其它":"jspic-06"
                }
            },
             
            "js导航菜单":{
                val:"jsnav",
                items:{
                    "js动画菜单":"jsnav-01",
                    "js下拉菜单":"jsnav-02",
                    "js手风琴菜单":"jsnav-03",
                    "js导航其它":"jsnav-04"
                }
            },
             
            "js选项卡特效":{
                val:"jstab",
                items:{
                    "js选项卡切换":"jstab-01",
                    "js滑动选项卡":"jstab-02"
                }
            },
             
            "js文字特效":{
                val:"jsfont",
                items:{
                    "js文字滚动":"jsfont-01",
                    "js文字切换":"jsfont-02",
                    "js文字其它":"jsfont-03"
                }
            },
             
            "js表单特效":{
                val:"jsform",
                items:{
                    "js表单验证":"jsform-01",
                    "js表单美化":"jsform-02",
                    "js表单其它":"jsform-03"
                }
            },
             
            "js滚动条美化":{
                val:"js-scroll",
                items:{}
            },
             
            "js评分,进度条,日期时间":{
                val:"js-rate",
                items:{}
            },
             
            "js提示框,弹出层,浮动层":{
                val:"js-div",
                items:{}
            },
             
            "js其它特效":{
                val:"js-other",
                items:{}
            }
             
        }
    },
     
    "flash特效":{
        val:"flash",
        items:{
             
            "图片特效":{
                val:"flash-pic",
                items:{}
            },
             
            "导航菜单":{
                val:"flash-nav",
                items:{}
            },
             
            "文字特效":{
                val:"flash-font",
                items:{}
            },
             
            "其它":{
                val:"flash-other",
                items:{}
            }
             
        }
    },
     
    "div+css教程":{
        val:"divcss",
        items:{
             
            "div+css布局":{
                val:"divcss-layout",
                items:{}
            },
             
            "div+css菜单":{
                val:"divcss-nav",
                items:{}
            },
             
            "css3教程":{
                val:"div-css3",
                items:{}
            },
             
            "其它":{
                val:"divcss-other",
                items:{}
            }
             
        }
    },
     
    "html5教程":{
        val:"html5",
        items:{
             
            "html5特效":{
                val:"html5-tx",
                items:{}
            },
             
            "html5图表":{
                val:"html5-map",
                items:{}
            },
             
            "其它":{
                val:"html5-other",
                items:{}
            }
             
        }
    }
     
 
};
 
var defaults = {
    s1:'mainselect',
    s2:'midselect',
    s3:'backselect'
};
 
$(function(){
    threeSelect(defaults);
});
 
function threeSelect(config){
    var $s1=$("#"+config.s1);
    var $s2=$("#"+config.s2);
    var $s3=$("#"+config.s3);
    var v1=config.v1?config.v1:null;
    var v2=config.v2?config.v2:null;
    var v3=config.v3?config.v3:null;
    $.each(threeSelectData,function(k,v){
        appendOptionTo($s1,k,v.val,v1);
    });
     
    $s1.change(function(){
        $s2.html("");
        $s3.html("");
        if(this.selectedIndex==-1)
        return;
         
        var s1_curr_val = this.options[this.selectedIndex].value;
         
        $.each(threeSelectData,function(k,v){
            if(s1_curr_val==v.val){
                if(v.items){
                    $.each(v.items,function(k,v){
                        appendOptionTo($s2,k,v.val,v2);
                    });
                }
            }
        });
     
        if($s2[0].options.length==0){
            appendOptionTo($s2,"...","",v2);
        }
         
        $s2.change();
         
    }).change();
     
    $s2.change(function(){
        $s3.html("");
        var s1_curr_val = $s1[0].options[$s1[0].selectedIndex].value;
        if(this.selectedIndex==-1)
        return;
         
        var s2_curr_val = this.options[this.selectedIndex].value;
         
        $.each(threeSelectData,function(k,v){
            if(s1_curr_val==v.val){
                if(v.items){
                    $.each(v.items,function(k,v){
                        if(s2_curr_val==v.val){
                            $.each(v.items,function(k,v){
                                appendOptionTo($s3.show(),k,v,v3);
                            });
                        }
                    });
                     
                    if($s3[0].options.length==0){
                        appendOptionTo($s3.hide(),"...","",v3);
                    }
                }
            }
        });
         
    }).change();
     
    function appendOptionTo($o,k,v,d){
 
        var $opt=$("<option>").text(k).val(v);
         
        if(v==d){
            $opt.attr("selected", "selected")
        }
        $opt.appendTo($o);
    }
     
}
</script>

 html代码很简单:

1
2
3
<select id="mainselect" name="mainselect" style="width:120px;"></select>
<select id="midselect" name="midselect" style="width:220px;"></select>
<select id="backselect" name="backselect" style="width:160px;"></select>

 

posted on   JoeYoung  阅读(2517)  评论(0编辑  收藏  举报
编辑推荐:
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
阅读排行:
· Sdcb Chats 技术博客:数据库 ID 选型的曲折之路 - 从 Guid 到自增 ID,再到
· 语音处理 开源项目 EchoSharp
· 《HelloGitHub》第 106 期
· Spring AI + Ollama 实现 deepseek-r1 的API服务和调用
· 使用 Dify + LLM 构建精确任务处理应用
< 2025年1月 >
29 30 31 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 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示