Latest web development tutorials

HTML onkeypress event properties

HTML Event Attributes HTML Event Attributes

Examples

Run the script when you press the button:

<input type="text" onkeypress="displayResult()">

try it"

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support onkeypress event attributes


Definition and Usage

onkeypress property triggered when the key is pressed.

Tip: onkeypress events related to the event firing order:

  1. onkeydown
  2. onkeypress
  3. onkeyup

Note: onkeypress event so the browser can not trigger all the keys (for example: ALT, CTRL, SHIFT, ESC ).If only whether the user has pressed a key detection, you can use onkeydown substituted, onkeydown is triggered all the keys.

Note: onkeypress attribute can not be used with the following elements: <base>, <bdo> , <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, or <title>.


Differences between HTML 4.01 and HTML5

no.


grammar

<elementonkeypress=" script ">

Property Value

描述
script 规定该onkeypress事件触发时执行的脚本。


HTML Event Attributes HTML Event Attributes