温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

jquery+css如何实现下拉列表功能

发布时间:2021-03-19 14:22:43 来源:亿速云 阅读:184 作者:小新 栏目:web开发

这篇文章主要介绍jquery+css如何实现下拉列表功能,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

具体代码如下所述:

<!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如何实现下拉列表功能”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI