In jQuery, which can be the key value of the keyboard or the key value of the mouse. JQuery discards the standard button attribute using which, which is a bit confusing.
Which is introduced by Firefox, which is not supported by IE. Which is intended to get the keyCode of the keyboard ).
In jQuery, which can be the key value of the keyboard or the key value of the mouse.
That is, when you determine which key the user presses the keyboard, you can use which to determine which key the user presses the mouse. It is used in one fell swoop.
Source code
The Code is as follows:
// Add which for key events
If (event. which = null & (event. charCode! = Null | event. keyCode! = Null )){
Event. which = event. charCode! = Null? Event. charCode: event. keyCode;
}
// Add which for click: 1 === left; 2 === middle; 3 === right
// Note: button is not normalized, so don't use it
If (! Event. which & event. button! = Undefined ){
Event. which = (event. button & 1? 1: (event. button & 2? 3: (event. button & 4? 2: 0 )));
}
The standard button uses 0, 1, 2 to indicate the left, center, and right-click of the mouse. JQuery's which uses 1, 2, 3.
Another unpleasant thing is that the event. which in the jQuery document does not mention that which can represent the mouse key value, but only the keyboard key value.
Comments in the source code are also misleading.
The Code is as follows:
// Add which for click: 1 === left; 2 === middle; 3 === right
Note that click is used, which makes it easy to use the click event. However, it is incorrect to obtain the click event.
Next, we will try the click event:
The Code is as follows: