js 右鍵菜單,支援不同對象不同菜單(相容IE、Firefox)_javascript技巧

來源:互聯網
上載者:User
裡面的代碼修改也比較簡單。
<html> <head> <title>ddd</title> <style> .DreamMenu { position:absolute; visibility:hidden; z-index:http://www.jb51.net/article/1http://www.jb51.net/article/0http://www.jb51.net/article/0; overflow:hidden; width:http://www.jb51.net/article/15http://www.jb51.net/article/0px; background-color:buttonface; border:dimgray http://www.jb51.net/article/1px solid !important; border:buttonhighlight menu menu buttonhighlight http://www.jb51.net/article/2px outset; padding:http://www.jb51.net/article/1px !important; padding:http://www.jb51.net/article/1px http://www.jb51.net/article/1px http://www.jb51.net/article/1px http://www.jb51.net/article/0px; font-size:http://www.jb51.net/article/1http://www.jb51.net/article/2px; } .DreamMenu ul { margin:http://www.jb51.net/article/1px; border-bottom:buttonhighlight http://www.jb51.net/article/1px solid; border-top:buttonshadow http://www.jb51.net/article/1px solid; } .DreamMenu a { display:block; width:http://www.jb51.net/article/1http://www.jb51.net/article/0http://www.jb51.net/article/0%; padding:http://www.jb51.net/article/1px http://www.jb51.net/article/2px http://www.jb51.net/article/2px http://www.jb51.net/article/2http://www.jb51.net/article/0px; cursor:default; text-decoration:none; color:#http://www.jb51.net/article/0http://www.jb51.net/article/0http://www.jb51.net/article/0http://www.jb51.net/article/0http://www.jb51.net/article/0http://www.jb51.net/article/0; } .DreamMenu a:hover { background:highlight; color:#ffffff; } </style> </head> <body menu='menu'> <!---這段js最好寫進檔案方便用,為了在5http://www.jb51.net/article/1能運行就直接寫進來了---> <script> /*** DreamCore - JsLib/Menu Date : Dec http://www.jb51.net/article/0http://www.jb51.net/article/3, http://www.jb51.net/article/2http://www.jb51.net/article/0http://www.jb51.net/article/06 Copyright: DreamSoft Co.,Ltd. Mail : Dream@Dreamsoft.Ca Author : Egmax Browser : IE5.http://www.jb51.net/article/0&+,Firefoxhttp://www.jb51.net/article/1.5&+,Netscape7.http://www.jb51.net/article/0&+ Update: ***/ if(!document.all) document.captureEvents(Event.MOUSEDOWN); var _Tmenu = http://www.jb51.net/article/0; var _Amenu = http://www.jb51.net/article/0; var _Type = 'A'; document.onclick = _Hidden; function _Hidden() { if(_Tmenu==http://www.jb51.net/article/0) return; document.getElementById(_Tmenu).style.visibility='hidden'; _Tmenu=http://www.jb51.net/article/0; } document.oncontextmenu = function (e) { _Hidden(); var _Obj = document.all ? event.srcElement : e.target; if(_Type.indexOf(_Obj.tagName) == -http://www.jb51.net/article/1) return; _Amenu = _Obj.getAttribute('menu'); if(_Amenu == 'null') 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() + 'px'; _Menu.style.top = _Top.toString() + 'px'; _Menu.style.visibility = 'visible'; _Tmenu = Eid; } /*** 可以支援其他標籤INPUT,IMG ***/ </script> <script>_Type='INPUT,A,DIV,BODY,IMG';</script> <!-----設定一個菜單層----> <div id="menu" class='DreamMenu'> 雲棲社區 百度 google 站長工具 <ul></ul> 列印 </div> <!-----設定一個菜單層----> <div id="menuhttp://www.jb51.net/article/2" class='DreamMenu'> 哈哈 我是個連結 好開心啊 查看 <ul></ul> 列印 </div> <!-----設定一個菜單層----> <div id="menuhttp://www.jb51.net/article/3" class='DreamMenu'> 哈哈 我是圖片 雖然打不開 查看 <ul></ul> 列印 </div> <table><tr><td height=http://www.jb51.net/article/1http://www.jb51.net/article/0http://www.jb51.net/article/0> <!-----設定一個菜單menu屬性----> 菜單http://www.jb51.net/article/1 菜單http://www.jb51.net/article/2 </td></tr></table> <div menu='menu'></div>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.