时间:2021-05-23 08:06:06 | 栏目:jquery | 点击:次
废话不多说了,直接给大家贴代码了,具体代码如下所示:
<!DOCTYPE html> <html> <head> <title>折叠菜单</title> <style> body{ background:grey; font-family:Microsoft Yahei; color:white; } .types a{ text-decoration:none; color:white; } .types ul{ display:none; } .files ul{ display:none; } </style> <script src="js/jquery-1.8.2.min.js"></script> <script> $(document).ready(function(){ var span=$(".files").find("span"); var ul=$(".files").find("ul"); span.bind("click",function(){ ul.each(function(){ $(this).css("display","none"); }); $(this).next().css("display","block"); }); }); </script> </head> <body> <ul class="files"> <li class="file"> <span>文件2-1</span> <ul> <li class="document"><a href="#">文档2-1-1</a></li> <li class="document"><a href="#">文档2-1-2</a></li> </ul> </li> <li class="file"> <span>文件2-2</span> <ul> <li class="document"><a href="#">菜单2-2-1</a></li> <li class="document"><a href="#">菜单2-2-2</a></li> </ul> </li> <li class="file"> <span>文件2-3</span> <ul> <li class="document"><a href="#">菜单2-3-1</a></li> <li class="document"><a href="#">菜单2-3-2</a></li> </ul> </li> </ul> </body> </html>