JS notation
document.getElementById ("Youji"). oncontextmenu=youjievent;//specify this element to bind right-click events
function Youjievent () {//The menu is displayed when the mouse is right-clicked
alert (item.name);
Return false;//the right-click effect of the shielded Web page itself
}
jquery notation
$ (function () {
$ (' #youji '). MouseDown (function (e) {
if (e.which==1) {
Alert ("This is the left-click event");
}else if (E.which = = 2) {
Alert ("This is a mid-strike event");
}else{
Alert ("This is the right-click event");
Return false;//block the right click event of the webpage itself
}
});
})
Right-click area of the mouse
<div id= "Youji" style= "width:200px; height:200px; Background-color: #1621E5 "></div>
Gets the XY coordinates of the mouse when clicked on the page
JS notation
var x, y;
function mouseposition (EV) {
if (Ev.pagex | | ev.pagey) {
return {x:ev.pagex, y:ev.pagey};
}
return {
X:ev.clientx + Document.body.scrollleft-document.body.clientleft,
Y:ev.clienty + document.body.scrolltop-document.body.clienttop
};
}
function MouseMove (EV) {
EV = EV | | window.event;
var mousepos = mouseposition (EV);
x = mousepos.x;
y = mousepos.y;
}
Document.onmousedown = MouseMove;
Get the mouse position on the page and right-click the event