<html>
<head>
????<meta?charset="UTF-8">
????<title>try</title>
</head>
<body>
<h2>驗(yàn)證實(shí)例</h2>
<form?ng-app=""?ng-controller="validateCtrl"?name="myForm"?novalidate>
<p>Username:<br>
<input?type="text"?name="user"?ng-model="user"?required>
<span?style="color:red"?ng-show="myForm.user.$dirty?&&?myForm.user.$invalid">
<span?ng-show="myForm.user.$error.required">Username?is?required.</span>
</span>
</p>
<p>Email:<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">Email?is?required.</span>
<span?ng-show="myForm.email.$error.email">Invalid?email?address.</span>
</span>
</p>
<p>
<input?type="submit"?ng-disabled="myForm.user.$dirty?&&?myForm.user.$invalid?||??
myForm.email.$dirty?&&?myForm.email.$invalid">
</p>
</form>
<script?src="http://apps.bdimg.com/libs/angular.js/1.2.15/angular.min.js"></script>
<script>
function?validateCtrl($scope)?{
????$scope.user?=?'John?Doe';
????$scope.email?=?'john.doe@gmail.com';
}
</script>
</body>
</html>
1 回答
已采納

李曉健
TA貢獻(xiàn)1036條經(jīng)驗(yàn) 獲得超461個(gè)贊
這是angular內(nèi)置的表單驗(yàn)證。如果開啟的話,他給表單里的所有需要驗(yàn)證的對(duì)象添加一些驗(yàn)證屬性,用于判斷驗(yàn)證結(jié)果。
$error就是驗(yàn)證結(jié)果的一相關(guān)屬性,可以根據(jù)它里面的一些值去判斷各種驗(yàn)證規(guī)則的驗(yàn)證結(jié)果
- 1 回答
- 0 關(guān)注
- 1781 瀏覽
添加回答
舉報(bào)
0/150
提交
取消