AngularJS ng-keypress 指令
AngularJS 實例
按下按鍵時執行的代碼:
<!DOCTYPE html><html><head><meta charset="utf-8"><script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script></head><body ng-app=""><input ng-keypress="count = count + 1" ng-init="count=0" /><h1>{{count}}</h1><p>該實例在輸入框每次按下按鍵時,計算變量"count" 會自動加1。 </p></body></html>定義和用法
ng-keypress 指令用於告訴AngularJS 在指定HTML 元素上按下按鍵時需要的操作。
ng-keypress指令不會覆蓋元素的原生onkeypress 事件, 事件觸發時,ng-keypress 表達式與原生的onkeypress 事件將都會執行。
按鍵敲擊的事件順序:
1.Keydown
2.Keypress
3.Keyup
文法
<element ng-keypress="expression"></element>
<input>, <select>, <textarea>, 和其他可編輯元素支持該指令。
參數值
| 值 | 描述 |
|---|---|
| expression | 按下按鍵執行的表達式。 |