先贴代码:

 1 <!DOCTYPE html>
 2 <html>
 3 <head lang="en">
 4     <meta charset="UTF-8">
 5     <title></title>
 6     <script type="text/javascript">
 7         window.onload = function(){
 8             //去掉默认的contextmenu事件,否则会和右键事件同时出现。
 9             document.oncontextmenu = function(e){
10                 e.preventDefault();
11             };
12             document.getElementById("test").onmousedown = function(e){
13                 if(e.button ==2){
14                     alert("你点了右键");
15                 }else if(e.button ==0){
16                     alert("你点了左键");
17                 }else if(e.button ==1){
18                     alert("你点了滚轮");
19                 }
20             }
21         }
22     </script>
23 </head>
24 <body>
25 
26 <div style="width: 400px;height:400px;margin:auto;border:1px solid pink" id="test"></div>
27 </body>
28 </html>
View Code

相关文章:

  • 2021-10-28
  • 2021-12-20
  • 2022-12-23
  • 2021-05-23
  • 2022-02-07
  • 2022-02-26
  • 2022-02-27
猜你喜欢
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案