<!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>