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

What is the keydown event in jquery?

藏色散人
藏色散人Original
2021-11-15 11:10:243311browse

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

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 d5fd7aea971a85678ba271703566ebfd 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!

Statement:
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