How does jquery distinguish between left and right mouse clicks

The method of jquery to distinguish between left-click and right-click: You can use the [event.which] property to distinguish right-click, the [event.which] property returns which keyboard key or mouse button is pressed on the specified event, the code is [switch (event. which)].



The operating environment of this tutorial: windows7 system, jquery 3.2.1 version, this method is applicable to all brand computers.

Recommendation: jquery video tutorial How to

distinguish between left-click and right-click in

jquery : In jquery, you can use the event.which property to distinguish right-click. The event.which property returns which keyboard key or mouse button was pressed on the specified event.

event.which provides 1, 2, or 3 for the left, center, and right mouse buttons, respectively.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

$('#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 Recommendation: javascript (video)

Guess you like

Origin blog.csdn.net/an17822307871/article/details/112663581