标签:javascript
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>上下文/鼠标右键 菜单示例</title> </head> <body> <div id="myDiv">右键点击文字区域获取上下文菜单</div> <ul id="myMenu" style="position:absolute;visibility:hidden;background-color:siler"> <li><a href="http://www.126.com">126.com</a></li> <li><a href="http://www.mozilla.org">FireFox</a></li> <li><a href="http://www.baidu.com">baidu</a></li> </ul> <script> window.addEventListener("load",function(event){ var div=document.getElementById("myDiv"); div.addEventListener("contextmenu",function(event){ event.preventDefault(); var menu=document.getElementById("myMenu"); menu.style.left=event.clientX+"px"; menu.style.top=event.clientY+"px"; menu.style.visibility="visible"; },false); },false); document.addEventListener("click",function(event){ document.getElementById("myMenu").style.visibility="hidden"; },false); /* window.addEventListener("beforeunload",function(event){ var message="really exit?"; event.returnValue=message; return message; },false); */ </script> </body> </html>
标签:javascript
原文地址:http://blog.csdn.net/zjc/article/details/41494193