Home > Web Front-end > JS Tutorial > js right-click menu, supports different menus for different objects (compatible with IE, Firefox)_javascript skills

js right-click menu, supports different menus for different objects (compatible with IE, Firefox)_javascript skills

PHP中文网
Release: 2016-05-16 18:35:44
Original
919 people have browsed it

Although the version is very old and no longer meets the standards, the code is worth referring to. Friends who need the right-click menu can refer to it. The code modifications in

are also relatively simple.

<html> 
<head> 
<title>ddd</title> 
<style> 
.DreamMenu { 
position:absolute; 
visibility:hidden; 
z-index:100; 
overflow:hidden; 
width:150px; 
background-color:buttonface; 
border:dimgray 1px solid !important; 
border:buttonhighlight menu menu buttonhighlight 2px outset; 
padding:1px !important; 
padding:1px 1px 1px 0px; 
font-size:12px; 
} 
.DreamMenu ul { 
margin:1px; 
border-bottom:buttonhighlight 1px solid; 
border-top:buttonshadow 1px solid; 
} 
.DreamMenu a { 
display:block; 
width:100%; 
padding:1px 2px 2px 20px; 
cursor:default; 
text-decoration:none; 
color:#000000; 
} 
.DreamMenu a:hover { 
background:highlight; 
color:#ffffff; 
} 
</style> 
</head> 
<body menu=&#39;menu&#39;> 
<!---这段js最好写进文件方便用,为了在51能运行就直接写进来了---> 
<script> 
/*** 
DreamCore - JsLib/Menu 
Date : Dec 03, 2006 
Copyright: DreamSoft Co.,Ltd. 
Mail : Dream@Dreamsoft.Ca 
Author : Egmax 
Browser : IE5.0&+,Firefox1.5&+,Netscape7.0&+ 
Update: 
***/ 
if(!document.all) document.captureEvents(Event.MOUSEDOWN); 
var _Tmenu = 0; 
var _Amenu = 0; 
var _Type = &#39;A&#39;; 
document.onclick = _Hidden; 
function _Hidden() 
{ 
if(_Tmenu==0) return; 
document.getElementById(_Tmenu).style.visibility=&#39;hidden&#39;; 
_Tmenu=0; 
} 
document.oncontextmenu = function (e) 
{ 
_Hidden(); 
var _Obj = document.all ? event.srcElement : e.target; 
if(_Type.indexOf(_Obj.tagName) == -1) return; 
_Amenu = _Obj.getAttribute(&#39;menu&#39;); 
if(_Amenu == &#39;null&#39;) return; 
if(document.all) e = event; 
_ShowMenu(_Amenu, e); 
return false; 
} 
function _ShowMenu(Eid, event) 
{ 
var _Menu = document.getElementById(Eid); 
var _Left = event.clientX + document.body.scrollLeft; 
var _Top = event.clientY + document.body.scrollTop; 
_Menu.style.left = _Left.toString() + &#39;px&#39;; 
_Menu.style.top = _Top.toString() + &#39;px&#39;; 
_Menu.style.visibility = &#39;visible&#39;; 
_Tmenu = Eid; 
} 
/*** 
可以支持其他标签INPUT,IMG 
***/ 
</script> 
<script>_Type=&#39;INPUT,A,DIV,BODY,IMG&#39;;</script> 
<!-----设置一个菜单层----> 
<div id="menu" class=&#39;DreamMenu&#39;> 
<a href=&#39;http://www.jb51.net&#39;>脚本之家</a> 
<a href=&#39;http://www.baidu.com&#39;> 百度</a> 
<a href=&#39;http://www.g.cn&#39;>google</a> 
<a href=&#39;http://tools.jb51.net&#39;>站长工具</a> 
<ul></ul> 
<a href=&#39;4&#39;>打印</a> 
</div> 
<!-----设置一个菜单层----> 
<div id="menu2" class=&#39;DreamMenu&#39;> 
<a href=&#39;0&#39;>哈哈</a> 
<a href=&#39;1&#39;>我是个链接</a> 
<a href=&#39;2&#39;>好开心啊</a> 
<a href=&#39;3&#39;>查看</a> 
<ul></ul> 
<a href=&#39;4&#39;>打印</a> 
</div> 
<!-----设置一个菜单层----> 
<div id="menu3" class=&#39;DreamMenu&#39;> 
<a href=&#39;0&#39;>哈哈</a> 
<a href=&#39;1&#39;>我是图片</a> 
<a href=&#39;2&#39;>虽然打不开</a> 
<a href=&#39;3&#39;>查看</a> 
<ul></ul> 
<a href=&#39;4&#39;>打印</a> 
</div> 
<table><tr><td height=100> 
<!-----设置一个菜单menu属性----> 
<a href=&#39;test.php&#39; menu=&#39;menu2&#39;>菜单1</a> 
<a href=&#39;test.php&#39; menu=&#39;menu2&#39;>菜单2</a> 
</td></tr></table> 
<div style=&#39;height:300;&#39; menu=&#39;menu&#39;></div> 
<img src=&#39;http://www.jb51.net/images/logo.gif&#39; menu=&#39;menu3&#39;>
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template