Prevent the default time

demo:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> .box{width:200px;height: 300px;background: #ccc;position: absolute;left:0;top:0;display: none} .box ul{margin: 0} </style> </head> <body> <!-- <a href="http://www.baidu.com">21321312</a> --> <class = div "Box"> <Li> Option 3 </ li> <Li> option. 1 </ Li> <UL> <Li> Option 2 </ li> <li> option. 4 </ Li> </ UL> </ div> </ body> <Script> var Obox document.querySelector = (. "Box" ) Document. the oncontextmenu = function (eve) {// oncontextmenu event fires and open the context menu when the user right-click in the element. var E = || Eve the window.event; obox.style.display = "Block" ; // return to false; // cancel the default event stopDefault (E); obox.style.left = e.offsetX + "PX" ; Obox .style.top = E. = function(){ obox.style.display = "none" } function stopDefault(e){ if(e.preventDefault){ e.preventDefault() //IE }else{ e.returnValue = false; //GOOGLE } } //封装函数 </script> </html>

 

Guess you like

Origin www.cnblogs.com/hy96/p/11419643.html