一個不錯的js製作的右鍵菜單

來源:互聯網
上載者:User
網上轉的,比我自己寫的方便拓展,所以轉過來~<html><head><script language='javascript'> /*******以下內容可以修改***************/ var mname=new Array( "首 頁", "修 改", "下 載", "刪 除", "新 建", "刷 新" ); //mname是菜單對應的名稱,數組的個數必須與下面murl對應 var murl=new Array( "window.open('http://www.cn5.cn','_blank','');", "alert('修改');", "alert('download');", "alert('delete');", "alert('new');", "alert('refresh');" ); //murl是菜單對應的操作,可以是任意javascript代碼但是要注意不要在裡面輸入\",只能用' //如果要實現跳轉可以這樣window.location='url'; var ph=18,mwidth=50;//每條選項的高度,菜單的總寬度 var bgc="#eee",txc="black";//菜單沒有選中的背景色和文字色 var cbgc="darkblue",ctxc="white";//菜單選中的選項背景色和文字色 var mover="this.style.background='"+cbgc+"';this.style.color='"+ctxc+"';" var mout="this.style.background='"+bgc+"';this.style.color='"+txc+"';" document.oncontextmenu=function() { mlay.style.display=""; mlay.style.pixelTop=event.clientY; mlay.style.pixelLeft=event.clientX; return false; } function showoff() { mlay.style.display="none"; } function fresh() { mlay.style.background=bgc; mlay.style.color=txc; mlay.style.width=mwidth; mlay.style.height=mname.length*ph; var h="<table width=100% height="+mname.length*ph+"px cellpadding=0 cellspacing=0 border=0>"; var i=0; for(i=0;i<mname.length;i++) { h+="<tr align=center height="+ph+" onclick=\""+murl[i]+"\" onMouseover=\""+mover+"\" onMouseout=\""+mout+"\"><td style='font-size:9pt;'>"+mname[i]+"</td></tr>"; } h+="</table>"; mlay.innerHTML=h; } </script> </head><body onClick="showoff();" onload="fresh();"> <div id="mlay" style="position:absolute;display:none;cursor:default;" onClick="return false;"></div> </body></html>

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.