您好,登錄后才能下訂單哦!
jsp頁面
- <%@ 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">
- <link type="text/css" rel="stylesheet" href="css/menu.css"></link>
- <script type="text/javascript" src="js/jquery-1.4.2.js"></script>
- <script type="text/javascript" src="js/menu.js"></script>
- <title>橫向縱向菜單</title>
- </head>
- <body>
- <ul>
- <li class="main">
- <a href="#">菜單項1</a>
- <ul>
- <li>
- <a href="#">子菜單項11</a>
- </li>
- <li>
- <a href="#">子菜單項12</a>
- </li>
- </ul>
- </li>
- <li class="main">
- <a href="#">菜單項2</a>
- <ul>
- <li>
- <a href="#">子菜單項21</a>
- </li>
- <li>
- <a href="#">子菜單項22</a>
- </li>
- </ul>
- </li>
- <li class="main">
- <a href="#">菜單項3</a>
- <ul>
- <li>
- <a href="#">子菜單項31</a>
- </li>
- <li>
- <a href="#">子菜單項32</a>
- </li>
- </ul>
- </li>
- </ul>
- <br />
- <br />
- <br />
- <ul>
- <li class="hmain">
- <a href="#">菜單項1</a>
- <ul>
- <li>
- <a href="#">子菜單項11</a>
- </li>
- <li>
- <a href="#">子菜單項12</a>
- </li>
- </ul>
- </li>
- <li class="hmain">
- <a href="#">菜單項2</a>
- <ul>
- <li>
- <a href="#">子菜單項21</a>
- </li>
- <li>
- <a href="#">子菜單項22</a>
- </li>
- </ul>
- </li>
- <li class="hmain">
- <a href="#">菜單項3</a>
- <ul>
- <li>
- <a href="#">子菜單項31</a>
- </li>
- <li>
- <a href="#">子菜單項32</a>
- </li>
- </ul>
- </li>
- </ul>
- </body>
- </html>
css樣式
- ul,li{
- /*清除ul和li上默認的小圓點*/
- list-style: none;
- }
- ul {
- /*清除子菜單的縮進值*/
- padding: 0;
- margin: 0;
- }
- .main,.hmain {
- background-p_w_picpath: url(../p_w_picpaths/title.gif);
- background-repeat: repeat-x;
- width: 120px;
- }
- li {
- background-color: #EEEEEE;
- }
- a {
- /*取消所有的下劃線*/
- text-decoration: none;
- padding-left: 20px;
- display: block;
- display: inline-block;
- width: 100px;
- padding-top: 3px;
- padding-bottom: 3px;
- }
- .main a, .hmain a {
- color: white;
- background-p_w_picpath: url(../p_w_picpaths/collapsed.gif);
- background-repeat: no-repeat;
- background-position: 3px center;
- }
- .main li a, .hmain li a {
- color: black;
- background-p_w_picpath: none;
- }
- .main ul, .hmain ul {
- display: none;
- }
- .hmain {
- float: left;
- margin-right: 1px;
- }
Jquery代碼
- $(document).ready(function(){
- //頁面中的DOM已經裝載完成時,執(zhí)行的代碼
- $(".main > a").click(function(){
- //找到主菜單項對應的子菜單項
- var ulNode = $(this).next("ul");
- /*
- if (ulNode.css("display") == "none") {
- ulNode.css("display","block");
- } else {
- ulNode.css("display","none");
- }
- */
- //ulNode.show("slow");//normal fast
- //ulNode.hide();
- //ulNode.toggle();
- //
- //ulNode.slideDown("slow");
- //ulNode.slideUp;
- ulNode.slideToggle();
- changeIcon($(this));
- });
- $(".hmain").hover(function(){
- $(this).children("ul").slideDown();
- changeIcon($(this).children("a"));
- },function(){
- $(this).children("ul").slideUp();
- changeIcon($(this).children("a"));
- });
- });
- /**
- * 修改主菜單的指示圖標
- */
- function changeIcon(mainNode) {
- if (mainNode) {
- if (mainNode.css("background-p_w_picpath").indexOf("collapsed.gif") >= 0) {
- mainNode.css("background-p_w_picpath","url('p_w_picpaths/expanded.gif')");
- } else {
- mainNode.css("background-p_w_picpath","url('p_w_picpaths/collapsed.gif')");
- }
- }
- }
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。