欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

折疊菜單及選擇器的運(yùn)用

 更新時間:2017年02月03日 12:13:14   作者:單先生  
本文主要介紹了折疊菜單及選擇器的運(yùn)用。具有很好的參考價值,下面跟著小編一起來看下吧

今天才發(fā)現(xiàn)原來篩選標(biāo)簽還可以這么用。

not(expr|ele | fn):從匹配元素的集合中刪除與指定表達(dá)式匹配的元素

下面demo中的使用:   var $category =  $(".sub-category-box>ul>li:gt(2):not(:last)");  //列表中索引大于2的,除了最后一個

filter(expr|obj|ele|fn) :r篩選出與指定表達(dá)式匹配的元素集合。這個方法用于縮小匹配的范圍。用逗號分隔多個表達(dá)式

$("ul>li").filter(":contains('佳能'),:contains('索尼'),:contains('三星')") .toggleClass("promoted");// 篩選出li標(biāo)簽中包含佳能、索尼、三星的標(biāo)簽,并設(shè)置class

找個demo中使用了這兩個方法。 突然感覺 jQuery真的是好強(qiáng)大。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
    .sub-category-box{
      width: 300px;
      border: 1px solid #000;
      margin: 20px auto;
      background-color: gainsboro;
    }
    .sub-category-box ul{
      list-style: none;
      width: 100%;
      overflow: hidden;
    }
    .sub-category-box ul li{
      float: left;
      width: 95px;
      height: 35px;
      text-align: center;
      background-color: darkorange;
      box-sizing: border-box;
      line-height: 40px;
      border-radius: 5px;
      margin: 2px;
    }
    .promoted{
      background-color: red !important;
      color: white !important;
    }
    .sub-category-box .show-more{
      width: 100%;
      height: 30px;
      border: 1px solid #000;
      text-align:center;
    }
    .sub-category-box .show-more a{
      text-decoration: none;
      line-height: 30px;
    }
  </style>
  <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
  <script>
    $(function () {
      //列表中索引大于2的,除了最后一個
      var $category = $(".sub-category-box>ul>li:gt(2):not(:last)");
      $category.hide();

      $('.show-more').click(function () {
        $category.stop().slideToggle(300);
        //篩選出符合條件的選擇器
        $("ul>li").filter(":contains('佳能'),:contains('索尼'),:contains('三星')")
             .toggleClass("promoted");
        return false;
      });
    });
  </script>
</head>
<body>
<div class="sub-category-box">
  <ul>
    <li>佳能</li>
    <li>索尼</li>
    <li>三星</li>
    <li>尼康</li>
    <li>松下</li>
    <li>卡西歐</li>
    <li>富士</li>
    <li>柯達(dá)</li>
    <li>理光</li>
    <li>明基</li>
    <li>松下</li>
    <li>卡西歐</li>
    <li>富士</li>
    <li>柯達(dá)</li>
    <li>海爾</li>
    <li>其他品牌</li>
  </ul>
<div class="show-more">
  <a href="javasript:void(0);">顯示全部品牌</a>
</div>
</div>
</body>
</html>

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關(guān)文章

最新評論