jQ选项卡案例

我的未来我决定 提交于 2019-11-27 06:06:45
<!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>

  

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!