The which in jquery can be either the key value of the keyboard or the key value of the mouse.
That is, when the user to determine which button the keyboard can be used which, when the user to determine which button to press the mouse can also use which. It's dual-use.
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 isn't 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));
}
It's also a bit of a bummer that the jquery document Event.which does not mention that which can represent the mouse button value, only refers to the keyboard key value.
The comments in the source code are also misleading.
Copy code code as follows:
Add which for click:1 = = left; 2 = = middle; 3 = = Right
Note that here is the click, it's easy to get people to use the Click event, but actually getting it in the Click event is wrong.
Try the Click event below:
Copy the Code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8"/>
<title></title>
<script src= "Http://code.jquery.com/jquery-1.6.1.js" > <script type= "text/web Effects" >
$ (document). Click (function (e) {
alert (E.which);
})
</script>
<body>
</body>