Home > Web Front-end > HTML Tutorial > The event attribute onkeypress that is triggered when the user presses a key (on the keyboard) in html

The event attribute onkeypress that is triggered when the user presses a key (on the keyboard) in html

黄舟
Release: 2017-11-06 09:35:38
Original
2968 people have browsed it

Example

Execute a piece of JavaScript when the user presses a key:

<input type="text" onkeypress="displayResult()">
Copy after login

Browser support

IE

Firefox

Chrome

Safari

Opera

All major browsers support the onkeypress attribute.

Definition and Usage

The onkeypress property is triggered when the user presses a key (on the keyboard).

Tip: The order of events relative to the onkeypress event:

onkeydown onkeypress onkeyup

Note: In any browser, the onkeypress event will not be triggered by all key presses (such as ALT , CTRL, SHIFT, ESC).

Note: The onkeypress attribute is not applicable to the following elements: , ,
, , ,