1 window.oncontextmenu = function(ev) { 2 var ul = document.getElementById("ul1"); 3 var oEvent = ev || event; 4 5 ul.style.left = oEvent.clientX + "px"; 6 ul.style.top = oEvent.clientY + "px"; 7 ul.style.display = "block"; 8 9 return false; 10 }; 11 12 //点击其他地方隐藏右键菜单 13 document.onclick = function() { 14 var ul = document.getElementById("ul1"); 15 ul.style.display = "none"; 16 };