自定义右键菜单
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> #div1{ width: 100px; height: 200px; border: 1px solid red; position: absolute; display: none; } </style> <script> window.onload=function(){ var oDiv=document.getElementById("div1"); // 右键菜单 document.oncontextmenu=function(ev){ var ev=ev||event; oDiv.style.display="block"; oDiv.style.left=ev.clientX+"px"; oDiv.style.top=ev.clientY+"px"; // 阻止默认行为 return false; } document.onclick=function(){ oDiv.style.display="none"; } } </script> </head> <body> <div id="div1"></div> </body> </html>