The keydown method in jquery is used to trigger a keydown event or specify a function to be run when a keydown event occurs. The syntax for triggering a keydown event is such as "$(selector).keydown()".
The operating environment of this article: windows7 system, jquery3.2.1 version, DELL G3 computer
What is the keydown event in jquery?
jQuery keydown() method
The complete key press process is divided into two parts: 1. The key is pressed; 2. The key is released.
The keydown event occurs when the button is pressed.
The keydown() method triggers the keydown event, or specifies a function to run when the keydown event occurs.
Note: If set on a document element, this event will occur regardless of whether the element has focus.
Tip: Use the .which property to determine which key was pressed (try it yourself).
Trigger the keydown event
Syntax
$(selector).keydown()
Bind the function to the keydown event
Syntax
$(selector).keydown(function)
Parameters
function Optional. Specifies the function to run when the keydown event occurs.
Example
When the keyboard key is pressed, set the background color of the field:
$("input").keydown(function(){ $("input").css("background-color","yellow"); });
Recommended learning:《jquery video tutorial》
The above is the detailed content of What is the keydown event in jquery?. For more information, please follow other related articles on the PHP Chinese website!