简单选项卡的使用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选项卡的简单使用</title>
</head>
<style>
    .container {   
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        right: 0;
        margin: auto;
        width: 800px;
        padding-top: 200px;
        cursor: pointer;
        user-select: none;
    }
    .container_cont {
        display: flex;
        justify-content: center;
        /* align-items: center; */
        width: 100%;
        margin-bottom: 100px;
    }
    .one,.two,.three {
        flex: 1;
        text-align: center;
        width: 0;
    }
    .boxb {
        width: 100% !important;
        height: 1px !important;
        color: red;
        background-color: red;
    }
    .text_two,.text_three {
        display: none;
    }
    .cur{
        color: red;
    }
    .box {
        width: 0;
    }
    .box_after {
        width: 100%;
        height: 1px;
        color: red;
        background-color: red;
        transition: all 1s;
    }
</style>
<body>
    <div class="container">
        <div class="container_cont">
            <div class="one">
                <p title="这是第一个选项卡">one</p>
                <div class="box boxb"></div>
            </div>
            <div class="two">
                <p title="这是第二个选项卡">two</p>
                <div class="box"></div>
            </div>
            <div class="three">
                <p title="这是第三个选项卡">three</p>
                <div class="box"></div>
            </div>
        </div>
        <div class="text_one">创建Html元素创建Html元素创建Html元素创建Html元素创建Html元素创建Html元素创建Html元素</div>
        <div class="text_two">设置css样式设置css样式设置css样式设置css样式设置css样式设置css样式设置css样式设置css样式</div>
        <div class="text_three">编写jquery代码编写jquery代码编写jquery代码编写jquery代码编写jquery代码编写jquery代码</div>
        

    </div>
</body>
</html>
<script src="./js/jquery.js"></script>
<script>
    $(".one").click(function(){
        $(".text_one").show();
        $(".text_two",).hide();
        $(".text_three").hide();
        $(".one div").addClass("box_after");
        $(".two div").removeClass("box_after");
        $(".three div").removeClass("box_after");
    })
    $(".two").click(function(){
        $(".text_two").show();
        $(".text_one").hide();
        $(".text_three").hide();
        $(".two div").addClass("box_after");
        $(".one div").removeClass("box_after");
        $(".three div").removeClass("box_after");
        $(".one .box").removeClass("boxb");
    })
    $(".three").click(function(){
        $(".text_three").show();
        $(".text_one").hide();
        $(".text_two").hide();
        $(".three div").addClass("box_after");
        $(".one div").removeClass("box_after");
        $(".two div").removeClass("box_after");
        $(".one .box").removeClass("boxb");
    })
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在JavaScript中,创建一个简易选项卡功能可以通过HTML结构和简单的脚本来实现。以下是一个基本的步骤和代码示例: 1. HTML结构: ```html <div class="tabs"> <ul id="tab-list"> <li><a href="#tab1">Tab 1</a></li> <li><a href="#tab2">Tab 2</a></li> <li><a href="#tab3">Tab 3</a></li> </ul> <div id="tab-content"> <div id="tab1" class="tab-panel active">Content for Tab 1</div> <div id="tab2" class="tab-panel">Content for Tab 2</div> <div id="tab3" class="tab-panel">Content for Tab 3</div> </div> </div> ``` 2. JavaScript/jQuery (为了简洁,这里使用jQuery): ```javascript <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { // 获取所有的选项卡链接 var tabLinks = $('#tab-list a'); // 为每个链接添加点击事件处理函数 tabLinks.on('click', function(e) { e.preventDefault(); // 阻止默认的页面跳转 // 获取当前链接的id var currentTabId = $(this).attr('href'); // 隐藏所有内容 $('.tab-panel').hide(); // 显示点击链接对应的内容 $('#' + currentTabId).show(); // 使当前链接变为激活状态 $(this).parent().addClass('active').siblings().removeClass('active'); }); }); </script> ``` 3. CSS样式(用于美化): ```css .tabs ul { list-style-type: none; margin: 0; padding: 0; display: flex; } .tabs li { margin-right: 10px; } .tabs a { display: block; padding: 10px; text-decoration: none; } .tab-panel { display: none; padding: 10px; } .active { background-color: #f1f1f1; } </style> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值