python-前端JQuery实现页面选项卡

本文介绍如何利用JQuery在前端实现选项卡功能。通过引入JS库,结合事件监听,动态切换不同页面内容。
摘要由CSDN通过智能技术生成

选项卡的实现是通过JQuery实现的,通过引进JS库,然后通过模块的点击事件,实现页面切换。

<!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>选项卡</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:gold;
        }

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

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

        .tab_cons .current{
            display:block;
        }
    </style>
    <script src="js/jquery-1.12.4.min.js"></script>
    <script>
        //ready函数
        $(function (){
        //获取模块
        var $btn = $('.tab_btns input ');
        var $div = $('.tab_cons div');
        //设置点击事件
        $btn.click(function(){
            //添加点击模块的样式类,删除其余模块的样式类。
            $(this).addClass('active').siblings().removeClass('active');
            //根据按钮的索引增加DIV模块的样式类,删除其余模块的样式类。
            $div.eq($(this).index()).addClass('current').siblings().removeClass('current');

        })
        
        }) 
            
       
    </script>
</head>

<body>
    <div class="tab_con">
        <div class="tab_btns">
            <input type="button" value="按钮一" class="active">
            <input type="button" value="按钮二">
            <input type="button" value="按钮三">
        </div>
        <div class="tab_cons">
            <div class="current">按钮一对应的内容</div>
            <div>按钮二对应的内容</div>
            <div>按钮三对应的内容</div>
        </div>
       
    </div>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值