如何使用angularjs实现表单验证
<!DOCTYPE html> <html ng-app="myApp"> <head> <title>angularjs-validate</title> <script type="text/javascript" src="js/angular.min.js"></script> </head> <body> <form name="form1" id="form1"> 账号:<input type="text" name="username" ng-model="username" required> <span style="color:red" ng-show="form1.username.$dirty && form1.username.$invalid"> <span ng-show="form1.username.$error.required">请输入账号</span> </span> <br /> 邮箱:<input type="text" name="email" ng-model="email" required> <span style="color:red" ng-show="form1.email.$dirty && form1.email.$invalid"> <span ng-show="form1.email.$error.required">请输入邮箱</span> </span> <p> <input type="submit" ng-disabled="form1.username.$dirty && form1.username.$invalid || form1.email.$dirty && form1.email.$invalid"> </p> </form> <script> var app = angular.module('myApp', []); </script> </body> </html>