Home > Web Front-end > Front-end Q&A > What is the keydown event in jquery?

What is the keydown event in jquery?

藏色散人
Release: 2021-11-15 11:10:24
Original
3314 people have browsed it

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()".

What is the keydown event in jquery?

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()
Copy after login

Bind the function to the keydown event

Syntax

$(selector).keydown(function)
Copy after login

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");
});
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template