- <!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>
AngularJs获取焦点与失去焦点时的表单验证
最新推荐文章于 2024-08-27 20:56:01 发布