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
View sourceprint? 01 // Add which for key events
02 if (event. which = null & (event. charCode! = Null | event. keyCode! = Null )){
03 event. which = event. charCode! = Null? Event. charCode: event. keyCode;
04}
05
06 // Add which for click: 1 === left; 2 === middle; 3 === right
07 // Note: button is not normalized, so dont use it
08 if (! Event. which & event. button! = Undefined ){
09 event. which = (event. button & 1? 1: (event. button & 2? 3: (event. button & 4? 2: 0 )));
10}
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.
View sourceprint? 1 // 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:
View sourceprint? 01 <! DOCTYPE html>
02
03
04 <meta charset = "UTF-8"/>
05 <title> </title>
06 <script src ="Http://code.jquery.com/jquery-1.6.1.js> </script>
07 <script type = "text/javascript">
08 $ (document). click (function (e ){
09 alert (e. which );
10 })
11
12 </script>
13
14 <body>
15 </body>
16
Test results: IE6/7/8 IE9 Firefox4 Chrome12 Safari Opera
Click 0 1 1 1 1 1 (alert pops up continuously) 1
Click the middle key and do not respond 2 2 2 2 (alert pops up without stopping ).
Right-click, only right-click, and only right-click
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.