jQuery keydown () method
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:
- keydown - key pressed process
- the KeyPress - key is pressed
- 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 事件触发时运行的函数。 |
More examples
Determines which key was pressed
How event.which property to determine which key was pressed.