首页 > 学院 > 开发设计 > 正文

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

2019-11-09 16:15:10
字体:
来源:转载
供稿:网友
<!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>  
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表