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. |