This article mainly introduces the form verification function implemented by AngularJS to obtain focus and lose focus. It involves AngularJS's use of ng-blur and ng-focus to monitor form event related operating techniques. Friends who need it can refer to it. I hope it can help. Everyone.
<!DOCTYPE html> <html ng-app="formExample"> <head> <meta charset="UTF-8"> <title></title> <script src="../js/angular.js"></script> <script> angular.module('formExample', []) .controller('FormController', ['$scope', function($scope) { $scope.userType = 'guest'; $scope.change = false; }]); </script> </head> <body> <form name="myForm" ng-controller="FormController"> userType: <input name="input" ng-model="userType" ng-blur="change=true" ng-focus="change=false" required> <span class="error" ng-show="myForm.input.$error.required && change">必填项</span><br> </form> </body> </html>
Running effect:
Related recommendations:
blur() in jquery loses focus and focus() obtains the focus event
How Use the Page Visibility API of html5 to achieve focus js events
The above is the detailed content of Detailed explanation of the form validation function when gaining focus and losing focus implemented by AngularJS. For more information, please follow other related articles on the PHP Chinese website!