jQuery实现常见的隐藏与展示列表效果示例

 更新时间:2018年06月04日 14:24:47   作者:前端爱我  
这篇文章主要介绍了jQuery实现常见的隐藏与展示列表效果,结合完整实例形式分析了jQuery事件响应及针对页面元素属性动态操作相关实现技巧,需要的朋友可以参考下

本文实例讲述了jQuery实现常见的隐藏与展示列表效果。分享给大家供大家参考,具体如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>www.jb51.net jquery品牌列表效果</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel=" rel="external nofollow" stylesheet">
<style>
  *{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
  }
  body {
    font: 16px/20px "Microsoft yahei,'微软雅黑'"
    color: #fff;
  }
  ul {
    list-style-type:none;
  }
  a {
    text-decoration: none;
    color: #000;
  }
  ul li {
    float: left;
    text-align: right;
  }
  .clear:before,.clear:after {
    content: "";
    clear: both;
    display: table;
    height: 0;
    overflow: hidden;
    zoom: 1;
  }
  .SubCategoryBox {
    width: 473px;
    margin: 0 auto;
    border: 1px solid;
  }
  .SubCategoryBox ul{
    padding: 5px 10px;
  }
  .SubCategoryBox ul li {
    padding: 5px;
  }
  .SubCategoryBox ul li:nth-child(3n-2) {
    width: 130px;
  }
  .SubCategoryBox ul li:nth-child(3n-1) {
    width: 161px;
    margin-right: 30px;
  }
  .SubCategoryBox ul li:nth-child(3n) {
    width: 130px;
  }
  .showmore {
    text-align: center;
  }
  .showmore a {
    background: #eef;
    color: #CFCFE0;
  }
  .hightlight a,.hightlight i {
    color: red;
    /* font-weight: bold; */
  }
</style>
</head>
<body>
    <div class="SubCategoryBox">
      <ul class="clear" id="bancon">
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >佳能</a><i>(30441)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >索尼</a><i>(30442)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >三星</a><i>(30443)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >尼康</a><i>(30444)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >松下</a><i>(30445)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >卡西欧</a><i>(30446)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >富士</a><i>(30447)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >柯达</a><i>(30448)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >宾得</a><i>(30449)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >理光</a><i>(30450)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >奥斯巴林</a><i>(30451)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >明基</a><i>(30452)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >爱国者</a><i>(30453)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >其他品牌相机</a><i>(30454)</i></li>
      </ul>
      <div class="showmore" id="showpp">
      <a href=""><span>显示全部品牌</span></a>
      </div>
    </div>
   <script src="http://cdn.bootcss.com/jquery/2.1.0/jquery.js"></script>
   <script>
   $(function(){
    var $target=$("#bancon li:gt(5):not(:last)");
    $target.hide();
    var $toggleBtn=$("#showpp a");
    $toggleBtn.click(function(){
      if($target.is(":visible")){
      $target.hide();
      $(this).find("span").text("显示所有品牌");
      $("ul li").removeClass('hightlight')
      }
      else {
        $target.show();
        $(this).find('span').text("精简显示品牌");
        $("ul li").filter(":contains('佳能'),:contains('尼康'),:contains('奥斯巴林')").addClass('hightlight')
      }
      return false;  /*阻止a标签的跳转*/
    });
   });
   </script>
</body>
</html>

使用在线HTML/CSS/JavaScript代码运行工具 http://tools.jb51.net/code/HtmlJsRun测试效果如下:

更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery扩展技巧总结》、《jQuery常用插件及用法总结》、《jQuery拖拽特效与技巧总结》、《jQuery表格(table)操作技巧汇总》、《jquery中Ajax用法总结》、《jQuery常见经典特效汇总》、《jQuery动画与特效用法总结》及《jquery选择器用法总结

希望本文所述对大家jQuery程序设计有所帮助。

相关文章

  • Jquery高级应用Deferred对象原理及使用实例

    Jquery高级应用Deferred对象原理及使用实例

    这篇文章主要介绍了Jquery高级应用Deferred对象原理及使用实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-05-05
  • jQuery使用$获取对象后检查该对象是否存在的实现方法

    jQuery使用$获取对象后检查该对象是否存在的实现方法

    下面小编就为大家带来一篇jQuery使用$获取对象后检查该对象是否存在的实现方法。小编觉而挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-09-09
  • jquery判断密码强度的验证代码

    jquery判断密码强度的验证代码

    本文主要介绍了jquery判断密码强度的验证代码,这是一个非常常见的功能,在输入密码的时候提示密码的强度,本文使用jQuery来实现,有需要的小伙伴可以参考下。
    2015-11-11
  • jquery中each循环的简单回滚操作

    jquery中each循环的简单回滚操作

    本篇文章主要介绍了jquery中each循环的简单回滚操作的相关知识,具有很好的参考价值。下面跟着小编一起来看下吧
    2017-05-05
  • Tab页界面 用jQuery及Ajax技术实现(php后台)

    Tab页界面 用jQuery及Ajax技术实现(php后台)

    到了B/S开发时代,网页前端布局也把Tab页的布局形式吸收了过来。特别是和Ajax技术结合起来,可以更充分发挥Tab页的良好表现力和数据缓存的优势,是一种良好的网页布局形式
    2011-10-10
  • jQuery操作iframe中js函数的方法小结

    jQuery操作iframe中js函数的方法小结

    这篇文章主要介绍了jQuery操作iframe中js函数的方法,结合实例形式总结分析了jQuery操作iframe中的元素、函数常用方法与注意事项,具有一定参考借鉴价值,需要的朋友可以参考下
    2016-07-07
  • Jquery瀑布流插件使用介绍

    Jquery瀑布流插件使用介绍

    瀑布流布局在目前貌似很火爆,具体的分析、原理、用到的知识等等可以看看以下几位牛人写的东西
    2012-10-10
  • jQuery中append()方法用法实例

    jQuery中append()方法用法实例

    这篇文章主要介绍了jQuery中append()方法用法,以实例形式较为详细的分析了append()方法的功能、定义与使用技巧,并对比分析了与text()方法的区别,需要的朋友可以参考下
    2014-12-12
  • jQuery实现判断滚动条到底部

    jQuery实现判断滚动条到底部

    这篇文章主要介绍了jQuery实现判断滚动条到底部的相关资料,需要的朋友可以参考下
    2015-06-06
  • 原生javascript实现的分页插件pagenav

    原生javascript实现的分页插件pagenav

    这几天要做一个前台页面,涉及到分页,不想自己去写所以在网上找jquery看有没有好用一点的分页组件,结果发现有很多,但是都很麻烦,看到了这个叫pagenav的发现相对来说还是很容易上手的,于是就直接用了,在我看来,能解决问题的办法就是好办法.越简单越好.
    2014-08-08

最新评论