zoukankan      html  css  js  c++  java
  • 【JS】HTML5事件

    1、contextmenu(windows的右键菜单的意思)

    <html>
    <head>
        <title>ContextMenu Event Example</title>
        <script type="text/javascript" src="EventUtil.js"></script>
    </head>
    <body>
        <div id="myDiv">Right click or Ctrl+click me to get a custom context menu. Click anywhere else to get the default context menu.</div>
        <ul id="myMenu" style="position:absolute;visibility:hidden;background-color:silver">
            <li><a href="http://www.nczonline.net">Nicholas' site</a></li>
            <li><a href="http://www.wrox.com">Wrox site</a></li>
            <li><a href="http://www.yahoo.com">Yahoo!</a></li>
        </ul>
        <script type="text/javascript">
            EventUtil.addHandler(window, "load", function(event){
                var div = document.getElementById("myDiv");
                            
                EventUtil.addHandler(div, "contextmenu", function(event){
                    event = EventUtil.getEvent(event);
                    EventUtil.preventDefault(event);
                    
                    var menu = document.getElementById("myMenu");
                    menu.style.left = event.clientX + "px";
                    menu.style.top = event.clientY + "px";
                    menu.style.visibility = "visible";
                });
                //设置click事件让菜单隐藏
                EventUtil.addHandler(document, "click", function(event){
                    document.getElementById("myMenu").style.visibility = "hidden";
                });
            });
    
        </script>
    </body>
    </html>

    2、window的beforeunload事件

    EventUtil.addHandler(window, "beforeunload", function(event){
        event = EventUtil.getEvent(event);
        var message = "I'm really going to miss you if you go.";
        //针对IE和fiefox
        event.returnValue = message;
        //针对safari和Chrome
        return message;
    });
  • 相关阅读:
    大数据Hadoop-2
    大数据Hadoop-1
    Consistent Hashing
    分支的创建、删除、切换、合并以及冲突解决
    windows WEB 高可用/可伸缩
    Oracle行转列、列转行的Sql语句总结
    从零到百亿互联网金融架构发展史---架构变迁
    WebJars
    springcloud(五):熔断监控Hystrix Dashboard和Turbine
    SpringBoot编写自定义的starter 专题
  • 原文地址:https://www.cnblogs.com/yangzhilong/p/3088761.html
Copyright © 2011-2022 走看看