下面看一段代码关于AngularJs获取焦点与失去焦点时的表单验证
<!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表单校验功能实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!
更多相关内容:
-
无相关信息