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-focus="count = count + 1" ng-init="count=0" /> <h1>{{count}}</h1> <p>This example calculates the variable "count" automatically and increments it every time the input box gets focused. 1。</p> </body> </html>Test to see ‹/›
ng-focus The directive is used to tell AngularJS what operation needs to be executed when the HTML element gets focused.
ng-focus The directive does not override the original onfocus event of the element, when the event is triggered,ng-focus Both the expression and the original onfocus event will be executed.
<element ng-focus="expression"></element>
<a>, <input>, <select>, <textarea>, and window objects all support this directive.
Value | Description |
---|---|
expression | Expression to be executed when the element gets focused. |