onkeypress event
Examples
Execute Javascript code when the user presses a button:
<input type="text" onkeypress="myFunction()">
try it"
Definition and Usage
It occurs when onkeypress event is a key press and release the keyboard keys.
Tip: onkeypress events associated with the sequence of events:
- onkeydown
- onkeypress
- onkeyup
Note: In all browsers onkeypress event is not suitable for all keys (such as: ALT, CTRL, SHIFT, ESC ).Monitor whether the user pressed a button, use onkeydown event, all browsers support onkeydown event.
grammar
In HTML:
<element
onkeypress="SomeJavaScriptCode">
In JavaScript:
object .onkeypress=function(){SomeJavaScriptCode};
参数 | 描述 |
---|---|
SomeJavaScriptCode | 必需。规定该事件发生时执行的 JavaScript。 |
Browser Support
All major browsers support onkeypress event
It supports HTML tags onkeypress event:
onkeypress property can be applied to all HTML elements except: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style> , and <title>.
Event objects