您好,欢迎访问一九零五行业门户网

AngularJS获取焦点及失去焦点时的表单验证功能实现方法

本文主要介绍了angularjs实现的获取焦点及失去焦点时的表单验证功能,涉及angularjs使用ng-blur、ng-focus针对表单事件监听相关操作技巧,需要的朋友可以参考下,希望能帮助到大家。
本文实例讲述了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>
运行效果:
相关推荐:
完美解决bootstrap模态框和select2合用时input无法获取焦点问题
jquery中blur()失去焦点与focus() 获取焦点事件
javascript - 怎么解决苹果5中input获取焦点,软键盘遮挡input的问题
以上就是angularjs获取焦点及失去焦点时的表单验证功能实现方法的详细内容。
其它类似信息

推荐信息