The example in this article explains how to implement the javascript mouse right-click menu and shares it with everyone for your reference. The specific content is as follows
Rendering:
Specific code:
<html> <head> <meta charset="gb2312" /> <title></title> <style> #menu{ border:solid 1px gray; width:100px; display:none; position:absolute; background-color:ghostwhite; margin: 0; padding: 0; list-style-type: none; } #menu>li{ border-bottom: dashed 1px gray; } </style> <script type="text/javascript"> window.onload=function(){ var oUl=document.getElementById('menu'); document.oncontextmenu=function(ev){ var oEvent=ev||event; //一定要加px,要不然chrom不认 oUl.style.top=oEvent.clientY+'px'; oUl.style.left=oEvent.clientX+'px'; oUl.style.display='block'; return false; } document.onclick=function(){ oUl.style.display='none'; } }; </script> </head> <body> <ul id="menu"> <li><a href="http://www.jb51.net/" target="_blank">脚本之家</a></li> <li><a href="http://www.jb51.net/" target="_blank">脚本之家</a></li> <li><a href="http://www.jb51.net/" target="_blank">脚本之家</a></li> <li><a href="http://www.jb51.net/" target="_blank">脚本之家</a></li> </ul> </body> </html>
I hope this article will be helpful to everyone learning JavaScript programming.