CSS+jQuery实现点击展开折叠菜单

<!DOCTYPE html> <html> <head> <title>折叠菜单</title> <style> body{ background:grey; font-family:Microsoft Yahei; color:whi...
<!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="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.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>

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
李沁雪
李沁雪

9 篇文章

作家榜 »

  1. admin 651 文章
  2. 粪斗 185 文章
  3. 王凯 92 文章
  4. 廖雪 78 文章
  5. 牟雪峰 12 文章
  6. 李沁雪 9 文章
  7. 全易 2 文章
  8. Stevengring 0 文章