AngularJs获取焦点与失去焦点时的表单验证

  1. <!DOCTYPE html>  
  2. <html ng-app="formExample">  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title></title>  
  6.     <script src="../js/angular.js"></script>  
  7.     <script>  
  8.         angular.module('formExample', [])  
  9.                 .controller('FormController', ['$scope', function($scope)  
  10.                 {  
  11.                     $scope.userType = 'guest';  
  12.                     $scope.change = false;  
  13.                 }]);  
  14.     </script>  
  15. </head>  
  16. <body>  
  17.   
  18. <form name="myForm" ng-controller="FormController">  
  19.     userType: <input name="input" ng-model="userType" ng-blur="change=true" ng-focus="change=false" required>  
  20.     <span class="error" ng-show="myForm.input.$error.required && change">必填项</span><br>  
  21. </form>  
  22. </body>  
  23. </html>  

猜你喜欢

转载自blog.csdn.net/u013184759/article/details/54945825