. 代碼如下:
<%@ 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>