Javascript选项卡

代码如下:

<!DOCTYPE html>
<html lang="en">

<head>
    <title>选项卡</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/style.css" rel="stylesheet">
    <style>
        #container {
            width: 405px;
            text-align: center;
            margin: 200px auto;
        }

        #container a {
            width: 100px;
            height: 40px;
            line-height: 40px;
            border-bottom: solid 1px #FF4400;
            border-left: solid 1px #FF4400;
            border-top: solid 1px #FF4400;
            text-decoration: none;
            float: left;
            color: black;
        }

        #container a:hover {
            color: #FF4400;
        }

        .clear {
            clear: both;
        }

        .content {
            display: none;
        }

        .content {
            width: 363px;
            height: 140px;
            border-bottom: solid 1px #FF4400;
            border-left: solid 1px #FF4400;
            border-right: solid 1px #FF4400;
            padding: 30px 0 0 40px;
        }

        .content img {
            text-align: center;
            padding: 30px auto;

        }

        #container a.on {
            background: #FF4400;
            color: #fff;
        }
    </style>

</head>

<body>
    <div id="container">
        <a href="#" class="on" count="0">电信</a>
        <a href="#" count="1">移动</a>
        <a href="#" count="2">联通</a>
        <a href="#" count="3" style="border-right: solid 1px #FF4400;">铁通</a>
        <div class="clear"></div>
        <div class="content" style="display:block;">
            <img src="../选项卡/images/1.png" />
        </div>
        <div class="content">
            <img src="../选项卡/images/2.png" />
        </div>
        <div class="content">
            <img src="../选项卡/images/3.png" />
        </div>

        <div class="content">
            <img src="../选项卡/images/4.png" />
        </div>
    </div>

    <script>
        var titles = document.getElementsByTagName("a");
        var content = document.getElementsByClassName("content");

        for (let index = 0; index < titles.length; index++) {
            titles[index].onclick = function () {
                for (let j = 0; j < titles.length; j++) {
                    titles[j].className = '';
                    content[j].style.display = 'none';
                }
                titles[index].className = 'on';
                // content[index].style.display = 'block';
                content[this.getAttribute('count')].style.display = 'block';
            }
        }
    </script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值