码迷,mamicode.com
首页 > Web开发 > 详细

AngularJS自定义表单验证

时间:2015-07-05 23:48:44      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

<!doctype html>
<html ng-app="myApp">
    <head>
        <script src="G:\\Source\\Repos\\GWD\\Gridsum.WebDissector.Website.ZC\\Gridsum.WebDissector.Website.ZC\\Pages\\dist\\assets\\lib\\angularjs\\angular.js"></script>
        <script type="text/javascript">
            var myModule = angular.module(‘myApp‘, []);
            myModule.controller(‘MyController‘, function ($scope, $timeout) {
                $scope.master= {};
                $scope.update = function(user) {
                    $scope.master= angular.copy(user);
                };
                $scope.reset = function() {
                    $scope.user = angular.copy($scope.master);
                };
                $scope.isUnchanged = function(user) {
                    return angular.equals(user, $scope.master);
                };
                $scope.reset();
            });       
        </script>
    </head>
    <body>
        <div ng-controller="MyController">
            <form name="form" class="css-form" novalidate>
                Name:
                <input type="text" ng-model="user.name" name="uName" required /><br />
                E-mail:
                <input type="email" ng-model="user.email" name="uEmail" required/><br />
                <div ng-show="form.uEmail.$dirty && form.uEmail.$invalid">Invalid:
                    <span ng-show="form.uEmail.$error.required">Tell us your email.</span>
                    <span ng-show="form.uEmail.$error.email">This is not a valid email.</span>
                </div>
                Gender: 
                <input type="radio" ng-model="user.gender" value="male" />male
                <input type="radio" ng-model="user.gender" value="female" />female<br />
                <input type="checkbox" ng-model="user.agree" name="userAgree" required />
                I agree: <input ng-show="user.agree" type="text" ng-model="user.agreeSign"
                required /><br />
                <div ng-show="!user.agree || !user.agreeSign">Please agree and sign.</div>
                <button ng-click="reset()" ng-disabled="isUnchanged(user)">RESET</button>
                <button ng-click="update(user)"
                ng-disabled="form.$invalid || isUnchanged(user)">SAVE</button>
            </form>
        </div>
    </body>
</html

  

AngularJS自定义表单验证

标签:

原文地址:http://www.cnblogs.com/chengshuiqiang/p/4623182.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!