Latest web development tutorials

jQuery keypress () method

jQuery Event Methods jQuery Event Methods

Examples

Calculated in the <input> field keystrokes:

$("input").keypress(function(){
$("span").text(i+=1);
});

try it"

Definition and Usage

The sequence of events associated with a keypress event:

  1. keyDown - key pressed process
  2. keypress - key is pressed
  3. keyUp - key is released

keypress () method triggers the keypress event, or when a predetermined function to run the event keypress event.

keypress event similar to the keydown event. This event occurs when the button is pressed.

However, keypress event does not trigger any key (such as ALT, CTRL, SHIFT, ESC). Please use the keydown () method to check these keys.


grammar

Trigger the selected element keypress events:

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

Add the function to the keypress event:

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

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


jQuery Event Methods jQuery Event Methods