温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

jQuery 之 TAB切换菜单(index索引版本)

发布时间:2020-07-20 21:01:03 来源:网络 阅读:436 作者:wx592bc92b285c7 栏目:web开发

代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery3.js"></script>
    <style>
        .menu{
            height: 38px;
            background-color: #eeeeee;
            line-height: 38px;
        }
        .menu .menu-item{
            float: left;
            border-right: 1px solid red;
            padding: 0 10px;
            cursor: pointer;
        }
        .content{
            min-height: 100px;
            border:2px solid #eeeeee;
        }
        .hide{
            display: none;
        }
        .active{
            background-color: #428bca;
        }
    </style>
</head>
<body>
    <div >
        <div class="menu">
            <div class="menu-item active">菜单一</div>
            <div class="menu-item">菜单二</div>
             <div class="menu-item">菜单三</div>
        </div>
        <div class="content">
            <div>内容一</div>
            <div class="hide">内容二</div>
            <div class="hide">内容三</div>
        </div>
    </div>
    <script>
        $(".menu-item").click(function () {
            //为当触发的标签添加active css
            $(this).addClass('active')
            //为当前触发标签的兄弟标签删除active css
            $(this).siblings().removeClass('active')
            //找到当前触发标签的索引位置值,如0,1,2
            var v = $(this).index();
            //根据标签索引位置值在内容菜单里查找位置也是等于v的标签,然后删除hide,再把兄弟标签添加hide
            $('.content').children().eq(v).removeClass('hide').siblings().addClass('hide')

        })
    </script>
</body>
</html>

展示

jQuery 之 TAB切换菜单(index索引版本)

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI