Home > Article > Web Front-end > jquery uses event.which method to obtain the code of keyboard input value_jquery
Example
shows which key was pressed:
$("input").keydown(function(event){
$("div").html("Key: " event.which);
});
Try it yourself
Definition and Usage
The which attribute indicates which key or button was pressed.
Syntax
event.which Parameter Description
event Required. Specifies the events to be checked. The event parameter comes from the event binding function.
jQuery discards the standard button attribute in favor of which, which is a bit puzzling.
which is introduced by Firefox and is not supported by IE. The original intention of which is to obtain the key value (keyCode) of the keyboard.
Which in jQuery can be the key value of the keyboard or the key value of the mouse.
That is, which can be used when determining which key of the keyboard the user pressed, and which can also be used when determining which key of the mouse the user pressed. It serves two purposes.
Source code: