当前位置: 首页 > 图文教程 > 网络编程 > Javascript > js右键菜单效果代码

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 js右键菜单效果代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 48 ::
收藏到网摘: n/a

将以下代码添加到<head>与</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>
----------------------------------
将以下代码替换<body>标签
----------------------------------
<body onClick="showoff();" onload="fresh();">
----------------------------------
在<body>与</body>之间插入以下代码
----------------------------------
<div id="mlay" style="position:absolute;display:none;cursor:default;" onClick="return false;"></div>
----------------------------------
完!!!
:)