用jQuery方法写tab栏的方法,点击方式

css代码:

        * {
            margin: 0;
            padding: 0;
        }
        
        .active {
            color: #fff;
            background-color: red;
        }
        
        .box {
            width: 600px;
            height: 400px;
        }
        
        li {
            flex: 1;
            list-style: none;
            text-align: center;
            line-height: 50px;
        }
        
        ul {
            width: 600px;
            height: 50px;
            margin: 0 auto;
            display: flex;
            background-color: #eee;
        }
        
        ol li {
            display: none;
        }
        
        .show {
            display: block;
        }

html代码块:


    <div class="box">
        <ul>
            <li class="active">商品介绍1</li>
            <li>商品介绍2</li>
            <li>商品介绍3</li>
            <li>商品介绍4</li>
            <li>商品介绍5</li>
        </ul>
        <ol>
            <li class="show">商品介绍</li>
            <li>规格与包装</li>
            <li>售后保障</li>
            <li>商品评价</li>
            <li>合作联系</li>
        </ol>
    </div>

引入jquery.js

<script src="./js/jquery-3.6.1.js"></script>

jQuery片段代码:

        $(function() {
            $('ul li').click(function() {
                var index = $(this).index()
                $(this).addClass('active').siblings('li').removeClass('active')
                $('ol li').eq(index).addClass('show').siblings('li').removeClass('show')
            })
        })

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值