zoukankan      html  css  js  c++  java
  • 自定义右键菜单(contextmenu)

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml">
     3 <head>
     4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
     5     <title>test05</title>
     6 </head>
     7 <body>
     8     <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>
     9     <ul id="myMenu" style="position:absolute;visibility:hidden;background-color:silver;">
    10         <li><a href="http://www.nczonline.net">Nicholas' site</a></li>
    11         <li><a href="http://www.wrox.com">Wrox site</a></li>
    12         <li><a href="http://www.yahoo.com">Yahoo!</a></li>
    13     </ul>
    14     <script type="text/javascript" src="eventutil.js"></script>
    15     <script type="text/javascript" src="test05.js"></script>
    16 </body>
    17 </html>
     1 EventUtil.addHandler(window, "load", function(event) {
     2     var div = document.getElementById("myDiv");
     3 
     4     EventUtil.addHandler(div, "contextmenu", function(event) {
     5         event = EventUtil.getEvent(event);
     6         EventUtil.preventDefault(event);
     7 
     8         var menu = document.getElementById("myMenu");
     9         menu.style.left = event.clientX + "px";
    10         menu.style.top = event.clientY + "px";
    11         menu.style.visibility = "visible";
    12     });
    13 
    14     EventUtil.addHandler(document, "click", function(event) {
    15         document.getElementById("myMenu").style.visibility = "hidden";
    16     });
    17 });
  • 相关阅读:
    5/14 补沙
    5/21 购填缝剂
    5/30 购水不漏
    6/1 购防水
    6/4 补防水
    5/21 人工
    5/7 增购电线
    6/2 补防水
    5/4 瓦工进场
    5/31 补瓷砖
  • 原文地址:https://www.cnblogs.com/qzsonline/p/2528374.html
Copyright © 2011-2022 走看看