我在做自定义右键菜单的时候,需要将一组div的右键菜单改为自定义的菜单,此时发现oncontextmenu的选择器不能用getElementsByName,只能用getElementById,是我的代码有问题还是就是只能用getElementById?js://自定义DIV右键菜单 var forRight = document.getElementById("right-menu"); document.getElementById("1").oncontextmenu = function(event){ var event = event || window.event; forRight.style.display = "block"; forRight.style.left = event.pageX+"px"; forRight.style.top = event.pageY+"px"; console.log("right menu id: "+this.id); //return false屏蔽默认右键事件 return false; }; document.getElementById("right-menu").oncontextmenu = function(){ return false; }; document.onclick=function(){ forRight.style.display = "none"; };
添加回答
举报
0/150
提交
取消