JavaScript 예제 5 (오른쪽 단추 메뉴)

1454 단어 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>

좋은 웹페이지 즐겨찾기