This example demonstrates how to assign an "onkeydown" event to an input element.
Press a key inside the text field to set a red background color.
<!DOCTYPE html> <html> <body> <input type="text" id="demo" onkeydown="myFunction()"> <script> function myFunction() {/*from ww w . j a va 2s .com*/ document.getElementById("demo").style.backgroundColor = "red"; } </script> </body> </html>
Bubbles: Cancelable: Event type: Supported HTML tags: | Yes Yes KeyboardEvent All HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title> |
---|