首頁  >  文章  >  web前端  >  jquery實作簡單合攏與展開網頁面板的方法_jquery

jquery實作簡單合攏與展開網頁面板的方法_jquery

WBOY
WBOY原創
2016-05-16 15:41:161140瀏覽

本文實例講述了jquery實作簡單合攏與展開網頁面板的方法。分享給大家供大家參考。具體如下:

這是一款網頁上常見的合攏(收縮)、伸展面板程式碼,使用了jQuery插件,程式碼更簡化,點擊面板的標題列即可折疊、或展開這一層,是網路上很流行的效果,由此可擴展出的功能還真挺多,只要動動腦筋,一定能做出來。

運作效果截圖如下:

線上示範網址如下:

http://demo.jb51.net/js/2015/jquery-simple-hidden-show-web-table-codes/

具體程式碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>网页上的层收缩、伸展面板代码</title>
<style type="text/css">
*{margin:0;padding:0;} 
body { font-size: 13px; line-height: 130%; padding: 60px }
#panel { width: 300px; border: 1px solid #0050D0 }
.head { padding: 5px; background: #96E555; cursor: pointer }
.content { padding: 10px; text-indent: 2em; border-top: 1px solid #0050D0;display:block; }
</style>
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(function(){
 $("#panel h5.head").toggle(function(){
  $(this).next("div.content").hide();
 },function(){
  $(this).next("div.content").show();
 })
})
</script>
</head>
<body>
<div id="panel">
 <h5 class="head">点击此处标题可展开</h5>
 <div class="content">
  一款基于jquery的伸展面板代码,点击面板的标题栏即可折叠、或展开这个层,貌似网上很流行的效果,引用了jQuery插件,使得本款效果更加的简洁实用, </div>
</div>
</body>
</html>

希望本文所述對大家的jquery程式設計有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn