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 codeCopy codeThe 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.Copy codeThe 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:Copy codeThe Code is as follows: <! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8"/>
<Title> </title>
<Script src = "http://code.jquery.com/jquery-1.6.1.js"> </script>
<Script type = "text/javascript">
$ (Document). click (function (e ){
Alert (e. which );
})
</Script>
</Head>
<Body>
</Body>
</Html>
Test Results
|
IE6/7/8 |
IE9 |
Firefox4 |
Chrome12 |
Safari |
Opera |
Left click |
0 |
1 |
1 |
1 |
1 (alert pops up continuously) |
1 |
Click the middle key |
No response |
2 |
2 |
2 |
2 (alert pops up constantly) |
No response |
Right-click |
Only right-click menu |
Only right-click menu |
3. Right-click the menu |
Only right-click menu |
Only right-click menu |
Only right-click menu |
You can see that the click event cannot be left, center, or right-click the corresponding values of 1, 2, and 3 as jQuery imagined. Different browsers are inconsistent and cannot be obtained by right-clicking. alert is continuously displayed in Safari.
Therefore, the mousedown/mouseup event should be used to achieve jQuery's idea. JQuery comments mislead people.
In addition, even if the mousedown/mouseup event is used, the value of the middle key cannot be obtained in Opera. Opera's disgusting behavior, jQuery, is powerless.