<! DOCTYPE html>
- I've seen a lot of code on the Internet before, but there's a bug that counts a lot of bugs, but I'm going to say it here. Mouse Right click on the event mouse release after the execution, because of the personal operating habits, when the right-click on the
- The 0*0 position of the button is also executed right button, so that the top shielding why also display the default browser menu, then we just need to display the elements of the mouse right button to shield off will not, welcome to reprint This code, thank you!
$ ("#btn"). Bind ("ContextMenu", function () { return false; }) $ ("#img"). MouseDown (function (e) { if (E.which = = 3) { //Gets the x-axis of the mouse var x = E.pagex; Gets the y-axis of the mouse var y = e.pagey; The position of the menu element we set is moved to the current right-click position of the mouse and displayed as $ ("#btn"). CSS ({' top ': Y + ' px ', ' left ': x + ' px ', ' Display ': ' block ', ' position ': ' Absolute '})} ) </script></body>
HTML Mouse Right-click menu code