ドキュメント

Events/keydown

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Events

keydown( )

Triggers the keydown event of each matched element.
This causes all of the functions that have been bound to the keydown event to be executed, and calls the browser's default keydown action on the matching element(s). This default action can be prevented by returning false from one of the functions bound to the keydown event. The keydown event usually fires when a key on the keyboard is pressed.

keydown( fn )

Bind a function to the keydown event of each matched element.
The keydown event fires when a key on the keyboard is pressed.
Arguments:
fnFunction
A function to bind to the keydown event on each of the matched elements.
function callback(eventObject) {
  this; // dom element
}
Examples:

To perform actions in response to keyboard presses on a page, try:

$(window).keydown(function(event){
  switch (event.keyCode) {
    // ...
    // different keys do different things
    // Different browsers provide different codes
    // see here for details: http://unixpapa.com/js/key.html    
    // ...
  }
});

NameType