jQuery实现Tab栏(选项卡)

效果图:鼠标滑过哪个button按钮,则下面显示对应button的内容

 

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .tab_con {
            width: 500px;
            height: 350px;
            margin: 50px auto 0;
        }

        .tab_btns {
            height: 50px;
        }

        .tab_btns input {
            width: 100px;
            height: 50px;
            background: #ddd;
            border: 0px;
            outline: none;
        }

        .tab_btns .active {
            background:pink;
        }

        .tab_cons {
            height: 300px;
            background:burlywood;
        }

        .tab_cons div {
            height: 300px;
            line-height: 300px;
            text-align: center;
            display: none;
            font-size: 30px;
        }

        .tab_cons .current {
            display: block;
        }
    </style>
    <script src='jquery-1.12.4.js'></script>
    <script>
    $(function(){
        $('input').mouseover(function(){

            $(this).addClass('active').siblings().removeClass()

            var index=$(this).index()
           $('.tab_cons div').eq(index).addClass('current').siblings().removeClass()
            //$(this).parent().next().children().eq(num).addClass('current').siblings().removeClass()
        })
    })
    </script>
</head>

<body>
    <div class="tab_con">
        <div class="tab_btns">
            <input type="button" value="button1" class="active">
            <input type="button" value="button2">
            <input type="button" value="button3">
        </div>
        <div class="tab_cons">
            <div class="current">我是button1啊</div>
            <div>我是button2啊</div>
            <div>我是button3啊</div>
        </div>
    </div>
</body>

</html>

 

版权声明:本文为qq_40808154原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_40808154/article/details/90339263