标签: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>
本文出自 “空空如也” 博客,请务必保留此出处http://6738767.blog.51cto.com/6728767/1583075
标签:javascript
原文地址:http://6738767.blog.51cto.com/6728767/1583075