js模拟桌面右键菜单,粘贴复制功能。如果有更好的办法也可以

<script type="text/javascript"> 

window.onload = function ()

{

var oMenu = document.getElementById("menu");

var aLi = oMenu.getElementsByTagName("li");

//加载后隐藏自定义右键菜单

oMenu.style.display = "none";

//菜单鼠标移入/移出样式

for (i = 0; i < aLi.length; i++)

{

//鼠标移入样式

aLi[i].onmouseover = function ()

{

this.className = "active"

};

//鼠标移出样式

aLi[i].onmouseout = function ()

{

this.className = ""

}

}

//自定义菜单

document.oncontextmenu = function (event)

{

var event = event || window.event;

var style = oMenu.style;

style.display = "block";

style.top = event.clientY + "px";

style.left = event.clientX + "px";

return false;

};

//页面点击后自定义菜单消失

document.onclick = function ()

{

oMenu.style.display = "none"

}

};

</script>


樱桃小丸子_0002
浏览 2195回答 1
1回答

慕郎_莲华

可以不错~~默认菜单应该设置成隐藏的~~~用js 去隐藏有可能会闪烁
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript