jQuery选项卡小练习

xml 复制代码
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>选项卡</title>
    <style>
        *{
            margin:0;
            border:0;
            padding:0;
        }
        .box{
            width: 1000px;
            margin:50px auto;
        }


        .tab dd{
            float:left;
            width:100px;
            padding:3px;
            margin-right:1px;
            background: #FF0000;
            color:#fff;
            text-align: center;
            cursor: pointer;
        }
        .tab dd:hover,.tab dd.active{
            background: #990000;
        }
        .goods{
            clear:both;
        }
        .goods div{
            display: none;
        }
        .goods div.current{
            display: block;
        }
    </style>
    <script src="../jquery-1.8.2.js"></script>
    <script>
        $(function(){
            $('dd').on('click',function(){
                $(this).addClass('active').siblings().removeClass('active');
                //拿到dd中所对应的下标
                var i=$(this).index();
                //以下标的值来找div的位置
                $('.goods div').hide().eq(i).show(1000)
            })
        })
    </script>
</head>
<body>
<div class="box">
    <dl class="tab">
        <dd class="active">手机</dd>
        <dd>家电</dd>
        <dd>服装</dd>
        <dd>数码</dd>
        <dd>玩具</dd>
    </dl>
    <div class="goods">
        <div class="current"><h1>手机商品</h1></div>
        <div><h1>家电商品</h1></div>
        <div><h1>服装商品</h1></div>
        <div><h1>数码商品</h1></div>
        <div><h1>玩具商品</h1></div>
    </div>
</div>


</body>
</html>
相关推荐
字节跳动开源20 分钟前
Midscene v1.0 发布 - 视觉驱动,UI 自动化体验跃迁
前端·人工智能·客户端
光影少年28 分钟前
三维前端需要会哪些东西
前端·webgl
王林不想说话1 小时前
React自定义Hooks
前端·react.js·typescript
heyCHEEMS1 小时前
Uni-app 性能天坑:为什么 v-if 删不掉 DOM 节点
前端
马致良1 小时前
三年前写的一个代码工具,至今已被 AI Coding 完全取代。
前端·ai编程
吾在学习路1 小时前
故事型总结:Swin Transformer 是如何打破 Vision Transformer 壁垒的?
人工智能·深度学习·transformer
橙某人1 小时前
LogicFlow 交互新体验:让锚点"活"起来,鼠标跟随动效实战!🧲
前端·javascript·vue.js
借个火er1 小时前
依赖注入系统
前端
借个火er1 小时前
项目介绍与环境搭建
前端
gustt1 小时前
React 跨层级组件通信:从 Props Drilling 到 useContext 的实战剖析
前端·react.js