复制代码 代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jqueryMenu</title>
<script type="text/javascript" src="js/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var allMenu=$("ul > a");//找到所有主菜单
allMenu.click(function(){
var list=$(this).nextAll('li');//找到当前被点击a节点的所有li兄弟节点
list.toggle('show');
});
});
</script>
</head>
<body>
<ul><a href="#">菜单一</a>
<li><a href="#">子菜单一</a></li>
<li><a href="#">子菜单二</a></li>
</ul>
<ul><a href="#">菜单二</a>
<li><a href="#">子菜单一</a></li>
<li><a href="#">子菜单二</a></li>
</ul>
</body>
</html>