zoukankan      html  css  js  c++  java
  • tab标签切换

    tab标签切换经常用到,所以写了一个简单的demo,支持ie6+浏览器。

    html代码

    <ul class="tab clearfix">
        <li>标签1</li>
        <li class="tab-active">标签2</li>
        <li>标签3</li>
    </ul>
    <div class="content">
        <div class="inner" style="display:none">
            标签1内容
        </div>
        <div class="inner">
            标签2内容
        </div>
        <div class="inner" style="display:none">
            标签3内容
        </div>
    </div>   

    css

    .content{
        border:1px solid #ddd;
        width:730px;
        height: 200px;
        background: #fff;
        *position: relative;
        *z-index: 10;
    }
    .tab{
        margin-top: 12px;
        width: 730px;
        height: 30px;
        list-style: none;
        margin-bottom: -1px;
        *position: relative;
        *z-index: 20;   
    }
    li{
        float: left;
        height: 28px;
        padding: 0 25px;
        border: 1px solid #DDDDDD;
        margin-right: 10px;
        line-height: 30px;
        cursor: pointer;
        background: #FAFAFA;
        color: #0461B1;
        font-size: 14px;
    }
    .tab-active{
        border-bottom:none;
        border-top-width: 2px;
        height: 28px;
        background: #fff;
        color: #333333;
        font-weight: bold;
    }

    js

     1 <script type="text/javascript">
     2     var lists = $('.tab li');
     3     var contents = $('.content .inner');
     4 
     5     function bindEvent(){
     6 
     7         lists.each(function(index_li, li){
     8             $(this).on('click', function(event){
     9 
    10                 lists.removeClass('tab-active');
    11                 $(this).addClass('tab-active');
    12 
    13                 contents.each(function(index_content, content){
    14                     if(index_li === index_content){
    15                         $(this).show();
    16                     }else{
    17                         $(this).hide();
    18                     }
    19                 });
    20             });
    21         });
    22     }
    23 
    24     function init(){
    25         bindEvent();
    26     }
    27 
    28     init();
    29 </script>

    效果

  • 相关阅读:
    Redis
    Log4Net
    EF脚手架生成数据库上下文(scaffold-dbcontext)
    quartz.net
    基于LNMP的小米电子商务网站平台
    LVS的DR模式负载均衡
    华为交换机SSH配置
    VMware ESXi 6.5安装
    VLAN划分
    华为路由设备SSH配置
  • 原文地址:https://www.cnblogs.com/zhaoran/p/3167117.html
Copyright © 2011-2022 走看看