java學習

          java學習

           

          jquery隱藏和顯示的切換


          <html >
          <head>
          <style type="text/css">
           *{ margin:0; padding:0;}
          body {font-size:12px;text-align:center;}
          a { color:#04D; text-decoration:none;}
          a:hover { color:#F50; text-decoration:underline;}
          .SubCategoryBox {width:600px; margin:0 auto; text-align:center;margin-top:40px;}
          .SubCategoryBox ul { list-style:none;}
          .SubCategoryBox ul li { display:block; float:left; width:200px; line-height:20px;}
          .showmore { clear:both; text-align:center;padding-top:10px;}
          .showmore a { display:block; width:120px; margin:0 auto; line-height:24px; border:1px solid #AAA;}
          .showmore a span { padding-left:15px; background:url(img/down.gif) no-repeat 0 0;}
          .promoted a { color:#F50;}
          </style>
          <!-- 引入jQuery -->
          <script src="../../scripts/jquery-1.3.1.js" type="text/javascript"></script>
          <script type="text/javascript">
          $(function(){                                     //  等待DOM加載完畢.
                  var $category = $('ul li:gt(5):not(:last)');             //  獲得索引值大于5的品牌集合對象(除最后一條)    
                  $category.hide();                                //  隱藏上面獲取到的jQuery對象。
                  var $toggleBtn = $('div.showmore > a');             //  獲取“顯示全部品牌”按鈕
                  $toggleBtn.click(function(){
                        if($category.is(":visible")){
                              $category.hide();                            //  隱藏$category
                              $('.showmore a span')
                                  .css("background","url(img/down.gif) no-repeat 0 0")      
                                  .text("顯示全部品牌");                  //改變背景圖片和文本
                              $('ul li').removeClass("promoted");            // 去掉高亮樣式
                        }else{
                              $category.show();                            //  顯示$category
                              $('.showmore a span')
                                  .css("background","url(img/up.gif) no-repeat 0 0")      
                                  .text("精簡顯示品牌");                  //改變背景圖片和文本
                              $('ul li').filter(":contains('佳能'),:contains('尼康'),:contains('奧林巴斯')")
                                  .addClass("promoted");                //添加高亮樣式
                        }
                      return false;                              //超鏈接不跳轉
                  })
          })
          </script>
          </head>
          <body>
          <div class="SubCategoryBox">
          <ul>
          <li ><a href="#">佳能</a><i>(30440) </i></li>
          <li ><a href="#">索尼</a><i>(27220) </i></li>
          <li ><a href="#">三星</a><i>(20808) </i></li>
          <li ><a href="#">尼康</a><i>(17821) </i></li>
          <li ><a href="#">松下</a><i>(12289) </i></li>
          <li ><a href="#">卡西歐</a><i>(8242) </i></li>
          <li ><a href="#">富士</a><i>(14894) </i></li>
          <li ><a href="#">柯達</a><i>(9520) </i></li>
          <li ><a href="#">賓得</a><i>(2195) </i></li>
          <li ><a href="#">理光</a><i>(4114) </i></li>
          <li ><a href="#">奧林巴斯</a><i>(12205) </i></li>
          <li ><a href="#">明基</a><i>(1466) </i></li>
          <li ><a href="#">愛國者</a><i>(3091) </i></li>
          <li ><a href="#">其它品牌相機</a><i>(7275) </i></li>
          </ul>
          <div class="showmore">
          <a href="more.html"><span>顯示全部品牌</span></a>
          </div>
          </div>
          </body>
          </html>

          posted on 2013-02-25 11:24 楊軍威 閱讀(3599) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 西充县| 易门县| 海阳市| 宜川县| 瓮安县| 桐梓县| 柯坪县| 垦利县| 扶余县| 呼伦贝尔市| 武定县| 三江| 吐鲁番市| 东宁县| 新丰县| 邵阳市| 威信县| 武宣县| 博爱县| 华容县| 青田县| 门头沟区| 黔西县| 钟山县| 讷河市| 南宫市| 洞口县| 额尔古纳市| 东丰县| 忻州市| 蓬安县| 凉山| 屯昌县| 临西县| 石狮市| 平昌县| 出国| 隆化县| 黄浦区| 定安县| 马尔康县|