AngularJS实现的获取焦点及失去焦点时的表单验证功能示例
本文实例讲述了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相关内容感兴趣的读者可查看本站专题:《AngularJS指令操作技巧总结》、《AngularJS入门与进阶教程》及《AngularJS MVC架构总结》
希望本文所述对大家AngularJS程序设计有所帮助。
相关推荐
Oranq 2017-09-09
nercon 2020-07-26
tztzyzyz 2020-07-20
nercon 2020-07-16
hzyuhz 2020-06-28
xustart0 2020-06-14
YAruli 2020-06-13
Kakoola 2020-05-17
ThinkingLink 2020-05-16
85443563 2020-04-30
xcguoyu 2020-03-04
somboy 2020-03-03
WangJiangNan 2020-01-07
Elements小帅 2020-01-16
Chinahdy 2020-01-10
nxcjh 2020-01-03