zoukankan      html  css  js  c++  java
  • 右键点击事件

    代码

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            *{
                margin:0;
                padding:0;
            }
            ul, ul li{
                list-style:none;
            }
            #list{
                width:80px;
                border:1px solid #ccc;
                box-shadow:2px 2px 2px #ccc;
                display:none;
                position: absolute;
            }
            #list li{
                border-bottom:1px solid #ccc;
                height:24px;
                line-height:24px;
                text-align:center;
                cursor: pointer;
            }
            #list li:last-child{
                border-bottom:none;
            }
        </style>
    </head>
    <body>
        <ul id="list">
            <li>查看</li>
            <li>删除</li>
            <li>复制</li>
            <li>粘贴</li>
        </ul>
    
        <script>
            var list = document.getElementById('list');
            /*
                1.阻止默认事件
                2.添加自己的事件,自定义菜单
            */
            // 右键事件 oncontextmenu
            document.oncontextmenu = function(ev){
                var eve = event || ev;
                eve.preventDefault();  // 阻止默认行为
                list.style.display = 'block';
                list.style.left = eve.clientX + 'px';
                list.style.top = eve.clientY + 'px';
            }
    
            // 左键事件
            document.onclick = function(){
                list.style.display = 'none';
            }
        </script>
    </body>
    </html>

    效果

  • 相关阅读:
    hdu3336 Count the string 扩展KMP
    hdu3294 Girls' research manacher
    hdu3068 最长回文 manacher
    hdu2886 Lou 1 Zhuang 数学/快速幂
    hdu2841 Visible Trees 容斥原理
    hdu2819 Swap 二分图匹配
    RandomAccess接口的使用
    java集合框架
    java集合简介
    JDK,JRE,JVM的区别与联系
  • 原文地址:https://www.cnblogs.com/shihaiying/p/13275932.html
Copyright © 2011-2022 走看看