Latest web development tutorials

jQuery keydown () method

jQuery Event Methods jQuery Event Methods

Examples

When the keyboard key is pressed, set <input> field background color:

$ ( "Input") keydown ( function () {$ ( "input") css ( "background-color", "yellow");.}).;

try it"

Definition and Usage

The sequence of events associated with the keydown event:

  1. keydown - key pressed process
  2. the KeyPress - key is pressed
  3. keyUp - key is released

keydown event occurs when the keyboard key is pressed.

keydown () method to trigger keydown event, or when a predetermined function to run the event keydown event.

Tip: Use event.which property to return which keyboard key is pressed.


grammar

Trigger the selected element keydown event:

$(selector).keydown() 尝试一下

Add the function to the keydown event:

$(selector).keydown(function) 尝试一下

参数 描述
function 可选。规定 keydown 事件触发时运行的函数。


Examples

More examples

Determines which key was pressed
How event.which property to determine which key was pressed.


jQuery Event Methods jQuery Event Methods