扫码关注官方订阅号
1
下拉框 2 下拉框 3 下拉框 4 下拉框
下拉框
点击1号a时显示出1号a下面对应的p,点击2号a时显示出2号a下面对应的p
认证高级PHP讲师
$("a").on("click",function(){ $(this).find("p").show(); $(this).siblings("a").find("p").hide() })
$("a").on("click",function(){ $('.dd').hide(); $(this).next().show(); })
<body> <p class="btn-wrap"> <a href="" class="aa">1</a> <a href="" class="aa">2</a> <a href="" class="aa">3</a> <a href="" class="aa">4</a> </p> <p class="select-wrap"> <p class="dd" style="display:none;"> 下拉框1 </p> <p class="dd" style="display:none;"> 下拉框2 </p> <p class="dd" style="display:none;"> 下拉框3 </p> <p class="dd" style="display:none;"> 下拉框4 </p> </p> <style type="text/css"> .aa { display: block; width: 25px; height: 25px; line-height: 20px; background-color: #eee; text-align: center; color: #000; float: left; } .dd { width: 100px; height: 40px; background-color: #eee; position: absolute; top: 20px; left: 0; display: block; cursor: pointer; } .aa:hover, .dd:hover { background-color: #f55; color: #fff; } </style> <script> $(document).on('click', '.aa', function() { var $index = $(this).index(); $('.dd').hide().eq($index).show(); return false; }); $(document).click(function() { //选中下拉框或点击空白区域收起下拉框 $('.dd').hide(); }) </script> </body>
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
认证高级PHP讲师