jQuery插件的使用 --- 手風琴的效果
在使用jQuery插件之前要導入需要的js文件和css文件,代碼如下:
- <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- %>
-
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
-
- <title>My JSP 'acc.jsp' starting page</title>
-
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css">
- -->
- <!-- 引入類庫文件 -->
- <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.7.1.min.js"></script>
- <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-ui-1.8.18.custom.min.js"></script>
- <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/ui-lightness/jquery-ui-1.8.18.custom.css">
- <script type="text/javascript">
- //頁面加載完畢觸發匿名函數
- $(document).ready(function(){
- //手風琴的效果
- $("#accordion").accordion(
- {
- header:"h3",//header設置的是頭標題,必須是h3,如果更改 ,沒有效果
- animated:"slide", //代表是否有動畫效果,默認值為slide,沒有默認的效果
- event:"mouseover",//event事件處理方式 click點擊事件滑過的效果
- autoHeigth:true,//自動設置高度
- //設置小圖標
- icon:{
- header:"ui-accordion-header",
- headerSelected:"ui-accordion-header"
- },
- active:1//設置默認展開的主題
- });
- //獲取手風琴中的options的值
- var activeVal=$("#accordion").accordion("option","active");
- //varactiveVal=$("#accordion").accordion("option","active",1);
- alert(activeVal);
- });
- </script>
- </head>
-
- <body>
- <div>
- <div>
- <h1>模仿手風琴的效果</h1>
- <div id="accordion">
- <div>
- <h3><a href="#">first</a></h3>
- <div>歡迎進入第一個內容</div>
- </div>
- <div>
- <h3><a href="#">second</a></h3>
- <div>歡迎進入第二個內容</div>
- </div>
- <div>
- <h3><a href="#">thrid</a></h3>
- <div>歡迎進入第三個內容</div>
- </div>
-
- </div>
- </div>
- </div>
- </body>
- </html>