我是靠谱客的博主 听话马里奥,这篇文章主要介绍jquery+css实现下拉列表功能,现在分享给大家,希望可以做个参考。

废话不多说了,直接给大家贴代码了,具体代码如下所述:

复制代码
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
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>fruit</title> <style type="text/css"> .hide { display: none; } div { float: left; width: 100%; } .selector-containter { margin-bottom: 10px; } .selector { width: 200px; background: #FFF; border: 1px solid #DDD; } .selector-hint { width: 178px; border: 1px solid #DDD; } .selector-expand { width: 8px; border: 1px solid #DDD; } .selector-collapse { width: 8px; border: 1px solid #DDD; } </style> <script src="jquery-3.2.1.min.js"></script> <script> $(document).ready(function() { //使用on方法,采用事件委派机制,selector-option-container中的内容为后续动态追加 $('.selector').on('click', '.selector-expand', function() { $(this).parent().children('.selector-option-container').children().remove(); $(this).parent().children('.selector-option-container').append('<div><input type="checkbox" name="fruitGroup" class="selector-checkbox"/></div><div class="selector-option">apricot</div>'); $(this).parent().children('.selector-option-container').append('<div><input type="checkbox" name="fruitGroup" class="selector-checkbox"/></div><div class="selector-option">banana</div>'); $(this).nextAll('.selector-option-container').removeClass('hide'); }); $('.selector').on('click', '.selector-collapse', function() { $(this).nextAll('.selector-option-container').addClass('hide'); }); $('.selector-t1').on('click', '.selector-option', function() { $(this).parent().parent().children('.selector-hint').text($(this).text()); $(this).parent().addClass('hide'); }); $('.selector-t1').on('click', '.selector-checkbox', function() { $(this).parent().parent().parent().children('.selector-hint').text($(this).parent().next().text()); //采用prop方法,对于值为布尔型的属性赋值 $(this).prop('checked', false); $(this).parent().parent().addClass('hide'); }); }); </script> </head> <body> <div id="titan" class="selector-containter"> <div id="fruit"> <div class="selector"> <div class="selector-hint">select fruit</div> <div class="selector-expand">+</div> <div class="selector-collapse">-</div> <div class="selector-option-container"> </div> </div> </div> </div> <div id="athena" class="selector-t1 selector-containter"> <div id="fruit"> <div class="selector"> <div class="selector-hint">select fruit</div> <div class="selector-expand">+</div> <div class="selector-collapse">-</div> <div class="selector-option-container"> </div> </div> </div> </div> </body> </html>

总结

以上所述是小编给大家介绍的jquery+css实现下拉列表功能,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

最后

以上就是听话马里奥最近收集整理的关于jquery+css实现下拉列表功能的全部内容,更多相关jquery+css实现下拉列表功能内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(107)

评论列表共有 0 条评论

立即
投稿
返回
顶部