• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
MC_Hotdog
Yeah, you're right I'm still riding that crappy bike
博客园    首页    新随笔    联系   管理    订阅  订阅

jQ选项卡案例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        ul{
            list-style: none;
        }
        a{
            text-decoration: none;
            color: white;
        }
        #box{
            width: 400px;
            height: 300px;
        }
        #box ul{
            width: 100%;
            overflow: hidden;
        }
        #box ul li{
            float: left;
            width: 50px;
            height: 50px;
            margin: 0 10px;
            background-color: red;
            text-align: center;
            line-height: 50px;
        }

        .active{
            width: 70%;
            height: 100px;
            background-color: blue;
            display: none;
        }

    </style>
</head>
<body>
    <div id="box">
        <ul>
            <li>
                <a href="javascript:void(0)">张三</a>
            </li>
            <li>
                <a href="javascript:void(0)">李四</a>
            </li>
            <li>
                <a href="javascript:void(0)">王五</a>
            </li>
            <li>
                <a href="javascript:void(0)">GAI六</a>
            </li>
        </ul>
        <div class="active"></div>
    </div>
    <script src="jquery-3.3.1.js"></script>
    <script>
        $(function () {
            $('#box ul li a').click(function () {

                $(this).css('color', 'yellow').parent('li').siblings('li').find('a').css('color', '#fff');
                var textVal = $(this).text();
                var changeVal = `<h1>${textval}</h1>`;
                $('.active').show().html(changeval);
                // val() 对标签里边的值获取
            })
        })
    </script>
</body>
</html>

  

posted @ 2019-08-13 22:42  MC_Hotdog  阅读(100)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3