鼠标右击菜单的简单实现源码

document.writeln('<div id=popmenuLayer style="position: absolute; width: 100; height: ; z-index: 998; display: none">');
document.writeln(' <span id=popmenuSelLayer  style="z-index: 999;position: absolute;top: 0; left: 18;background-color: #E2EBFC;line-height: 20px;display: "></span>');
document.writeln('</div>');

function getMenu(testSta,id)
{
var appPath = "http://"+window.location.host;
if(window.location.pathname.indexOf("/cityms") >= 0)
appPath += "/appName";

var menu  = document.all.popmenuLayer.style;

menu.left = event.x;
menu.top = event.y;
menu.display = 'none';

if(testSta == "0"){
menu.display = '';
var menuTmp;
menuTmp = "<a href='"+appPath+"/test/reqTest.action?id="+id+"' target='_blank'>测试请求</a>";
menuTmp += "<br/><a href='"+appPath+"/test/delete.action?id="+id+"' target='_blank'>删除</a>";
popmenuSelLayer.innerHTML = menuTmp;
}
event.returnValue=false;
}

document.onmouseup = function()
{
if (event.button==1)
{
closePopmenuLayer();
}
if (event.button==2||event.button==3)
{
var obj = document.elementFromPoint(event.x, event.y);
if(obj.id != null && obj.id != ""){
var arr = obj.id.split(",");
getMenu(arr[0],arr[1]);
arr = null;
}
obj = null;
}
}

document.oncontextmenu = function()
{
var rangeType = document.selection.type;
if(rangeType != "Text" && event.srcElement.type!='text')
{
return false;
}
else
{
return true;
}
}

function closePopmenuLayer()
{
document.all.popmenuLayer.style.display="none";
}


如果给你带来帮助,欢迎微信或支付宝扫一扫,赞一下。