Jquery method to distinguish left or right mouse clicks: You can use the [event.which] attribute to distinguish right clicks. The [event.which] attribute returns which keyboard key or mouse button was pressed on the specified event, code It is [switch (event.which)].
The operating environment of this tutorial: windows7 system, jquery3.2.1 version, thinkpad t480 computer.
Recommended: jquery video tutorial
##How to differentiate between left click and right click in jquery:
You can use theevent.which attribute in jquery to distinguish right clicks.
event.whichProperty returns which keyboard key or mouse button was pressed on the specified event.
$('#element').mousedown(function(event) { switch (event.which) { case 1: alert('Left Mouse button pressed.'); break; case 2: alert('Middle Mouse button pressed.'); break; case 3: alert('Right Mouse button pressed.'); break; default: alert('You have a strange Mouse!'); }});
Related free learning recommendations: javascript(Video)
The above is the detailed content of How to distinguish between left mouse button and right mouse click in jquery. For more information, please follow other related articles on the PHP Chinese website!