JS控制滑鼠點擊事件

來源:互聯網
上載者:User

標籤:

  滑鼠點擊事件就是當滑鼠點擊元素時,就會出現另一個視窗,類似於百度首頁中右上方的“登入”這個按鈕,當滑鼠點擊

登入時,就會出現登入視窗。大體的意思就是這樣,直接上代碼了,簡單易懂。

  <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登入消失</title>
    <style type="text/css">
    #log{
        width: 100px;height: 30px;
        background: green;
        text-align: center;
    }
    #login{
        margin: 0;padding: 0;
        display: inline-block;
        color: black;
        line-height: 30px;

    }
    .qq{
        position: absolute;
        left: 0;top: 0;
        width: 100%;height: 100%;
        background: black;
        opacity: 0.15;
        text-align: right;
    }
    .dian{
        text-decoration: none;
        font-size: 50px;
        width: 150px;
        height: 50px;
        background: white;
        display: block;
        margin: 100px auto 0px;
        color: black;
    }
    </style>
</head>
<body>
    <div id="log">
        <a href="#" id="login">登入</a>
    </div>
    <div class="qq">
        <a href="#" class="dian">×</a>
    </div>

    <script type="text/javascript">
    var login = document.getElementById(‘login‘);
    var qq = document.getElementsByClassName(‘qq‘);
    var dian = document.getElementsByClassName(‘dian‘);
    qq[0].style.display = ‘none‘;
    login.onclick = function(){
        qq[0].style.display = ‘block‘;
    }
    dian[0].onclick = function(){
        qq[0].style.display = ‘none‘;
    }

    </script>


</body>
</html>

 

一開始沒有點擊登入,直接重新整理的網頁

 

當點擊登入時,頁面就會變成這樣:

 

當點擊圖中的X號時,該頁面就會消失,結果就是第一張圖片。

 

JS控制滑鼠點擊事件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.