English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js">/script> </head> <body ng-app=""> <input ng-keydown="count = count" + 1" ng-init="count=0" /> <h1>{{count}}</h1> <p>This example automatically increments the variable "count" each time a key is pressed in the input box. 1。</p> </body> </html>Test to see ‹/›
ng-keydown The directive is used to tell AngularJS the operation required when a key is pressed on the specified HTML element.
ng-keydown The directive does not override the native onkeydown event of the element, when the event is triggered,ng-keydown Both the expression and the native onkeydown event will be executed.
The order of key press events:
Keydown
Keypress
Keyup
<element ng-keydown="expression"></element>
<input>, <select>, <textarea>, and other editable elements support this directive.
Value | Description |
---|---|
expression | Press the key to execute the expression. |