HTML onkeydownEvent Attribute

HTML 事件属性HTML Event Attributes

Example

Execute a script when a key is pressed:

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

Try it Yourself »

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the onkeydown event attribute


Definition and Usage

The onkeydown attribute triggers when the user presses a key (on the keyboard).

Tip:The event trigger order related to the onkeydown event:

  1. onkeydown
  2. onkeypress
  3. onkeyup

Note:The onkeydown attribute cannot be used on the following elements: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, or <title>.


Differences Between HTML 4.01 and HTML5

None.


Syntax

<element onkeydown="script">

Attribute Value

Value Description
script Specifies the script to be executed when the onkeydown event is triggered.


HTML 事件属性HTML Event Attributes Other Extensions