-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyForm.html
42 lines (37 loc) · 1.27 KB
/
myForm.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="angular/angular.min.js"></script>
</head>
<body>
<h2>案例</h2>
<!--novalidates html5新增属性,非必须,用于表单验证,禁止浏览器默认验证-->
<form ng-app="myApp" ng-controller="validateCtrl" name="myForm" novalidate>
<p>用户名:<br/>
<!--required 必填项-->
<input type="text" name="user" ng-model="user" required>
<span style="color:red" ng-show="myForm.user.$dirty && myForm.user.$invalid">
<span style="color:red" ng-show="myForm.user.$error.required">用户名是必须的</span>
</span>
</p>
<p>邮箱:<br/>
<input type="email" name="email" ng-model="email" required>
<span style="color:red" ng-show="myForm.email.$dirty && myForm.email.$invalid">
<span ng-show="myForm.email.$error.required">邮箱是必须的!</span>
<span ng-show="myForm.email.$error.email">邮箱是非法的!</span>
</span>
</p>
<p>
<input type="submit" ng-disabled="myForm.user.$dirty && myForm.user.$invalid || myForm.email.$dirty && myForm .email.$invalid">
</p>
</form>
<script>
var app=angular.module('myApp',[]);
app.controller('validateCtrl',function($scope){
$scope.user='强强';
$scope.email='[email protected]';
});
</script>
</body>
</html>