AngularJS ng-keypress
指令
示例
在每次按键时执行表达式
<input ng-keypress="count = count + 1" ng-init="count=0" />
<h1>{{count}}</h1>
自己动手试一试 »
定义和用法
The ng-keypress
directive tells AngularJS what to do when the keyboard is used on the specific HTML element.
The ng-keypress
directive from AngularJS will not override the element's original onkeypress event, both will be executed.
按键的顺序是
1. Keydown (按下)
2. Keypress (按键)
3. Keyup (抬起)
语法
<element ng-keypress="expression"></element>
支持 <input>、<select>、<textarea> 和其他可编辑元素。
参数值
值 | 描述 |
---|---|
expression | An expression to execute when a key is pressed. |