jQuery插件的使用 --- 手风琴的效果
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>