<!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标题怎么设置禁止跨行
js控制时间每秒自己运动
parabola.js实现抛物线与加入购物车功能
以上就是angularjs获取焦点以及操作焦点的详细内容。