Javascript onclick点击事件 鼠标点击实现显示与隐藏

 鼠标点击 使隐藏部分显示出来

效果图:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        a {
            text-decoration: none;
            color: #333;
            font-size: 16px;
        }
        .title p {
            display: none;
            color: #ccc;
        }
    </style>
</head>

<body>
    <h5 class="title" id="hh1">
        <a href="#" onclick="Change1()">我是链接 快点我</a>
        <p id="title-p1">我出现啦</p>
    </h5>
    <h5 class="title" id="hh2">
        <a href="#" onclick="Change2()">我是链接 快点我</a>
        <p id="title-p2">我出现啦</p>
    </h5>
    <h5 class="title" id="hh3">
        <a href="#" onclick="Change3()">我是链接 快点我</a>
        <p id="title-p3">我出现啦</p>
    </h5>


    <script>
        function Change1() {
            var hh1 = document.getElementById("title-p1");
            var hh2 = document.getElementById("title-p2");
            var hh3 = document.getElementById("title-p3");
            if (hh1.style.display == "" || hh1.style.display == "none") {
                hh1.style.display = "block"
                hh2.style.display = "none"
                hh3.style.display = "none"
            } else {
                hh1.style.display = "none"
            }
        }

        function Change2() {
            var hh2 = document.getElementById("title-p2");
            var hh1 = document.getElementById("title-p1");
            var hh3 = document.getElementById("title-p3");
            if (hh2.style.display == "" || hh2.style.display == "none") {
                hh2.style.display = "block"
                hh1.style.display = "none"
                hh3.style.display = "none"
            } else {
                hh2.style.display = "none"
            }
        }

        function Change3() {
            var hh3 = document.getElementById("title-p3");
            var hh1 = document.getElementById("title-p1");
            var hh2 = document.getElementById("title-p2");
            if (hh3.style.display == "" || hh3.style.display == "none") {
                hh3.style.display = "block"
                hh1.style.display = "none"
                hh2.style.display = "none"
            } else {
                hh3.style.display = "none"
            }
        }
    </script>
</body>

</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值