tab切换

作者: 璐璐熙可 | 来源:发表于2017-06-02 22:49 被阅读17次
    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>导航</title>
        <script src="js/jquery-1.10.2.js"></script>
    <style>
        *{
            margin: 0;
            padding:0;
            list-style: none;
            font-size: 14px;
            text-decoration: none;
        }
        .tab{
            width:895px;
            height:400px;
            margin:0 auto;
            border:1px solid #eee;
            overflow: hidden;
        }
        .notice-tit{
            height:50px;
            position: relative;
            background: #fff;
        }
        .notice-tit ul{
            position: absolute;
            left:-1px;
        }
        .notice-tit li{
            float: left;
            width:297px;
            height:49px;
            line-height: 49px;
            border:1px solid #eee;
        }
        .notice-tit li a{
            display: block;
            text-align:center;
        }
        .notice-tit li.active a{
            background: #f7f7f7;
            color:green;
        }
        .notice-tit li.kl{
            border-right:none;
        }
        .notice-tit li a:hover{
            background: #f7f7f7;
            color:green;
        }
        .notice-con li a{
            
        }
        .notice-con li{
            display: none;
            float: left;
            width: 298px;
            height:25px;
        }
        .notice-con li.active{
            display: block;
        }
    </style>    
    </head>
    <body>
        <div id="tab" class="tab">
            <div id="notice-tit" class="notice-tit">
                <ul>
                    <li class="active"><a href="#" >tab1</a></li>
                    <li><a href="#">tab2</a></li>
                    <li class="kl"><a href="#">tab3</a></li>
                </ul>
            </div>
            <div id="notice-con" class="notice-con">
                    <ul>
                        <li class="active"><a href="#" >内容1</a></li>
                        <li><a href="#">内容2</a></li>
                        <li><a href="#">内容3</a></li>
                    </ul>
            </div>
        </div>
    <script>
        $(function(){
            var $Tab_li=$('#notice-tit');
            $Tab_li.on('click','li',function(e){
            show($(this));
            var index =$(this).index();
            show($('#notice-con li').eq(index));
            });
            })
            function show($dom){
                $dom.addClass('active').siblings().removeClass('active');
            }
    </script>
    </body>
    </html>
    
    
    
    
    
    

    相关文章

      网友评论

          本文标题:tab切换

          本文链接:https://www.haomeiwen.com/subject/ghcpfxtx.html