JavaScript 右键菜单

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <title></title>
 6         <style>
 7             * {margin: 0; padding: 0; list-style: none;}
 8             #div1{width: 80px;background-color:#CCC;position: absolute;border: 1px solid black; display: none;}
 9         </style>
10         <script>
11             document.oncontextmenu=function(ev){
12                 var oEvent=ev||event;
13                 var oDiv=document.getElementById('div1');
14                 
15                 oDiv.style.display='block';
16                 oDiv.style.left=oEvent.clientX+'px';
17                 oDiv.style.top=oEvent.clientY+'px';
18 
19                 return false;
20             }
21 
22             document.onclick=function(){
23                 var oDiv=document.getElementById('div1');
24 
25                 oDiv.style.display='none';
26             }
27         </script>
28     </head>
29     <body>
30         <div id="div1">
31             <ul>
32                 <li>aaa</li>
33                 <li>bbb</li>
34                 <li>ccc</li>
35                 <li>ddd</li>
36             </ul>
37         </div>
38     </body>
39 </html>
右键菜单

 

posted @ 2020-04-29 09:13  孝文  阅读(130)  评论(0编辑  收藏  举报