ng-model 指令根據(jù)表單域的狀態(tài)添加/移除以下類:
- ng-empty
- ng-not-empty
- ng-touched
- ng-untouched
- ng-valid
- ng-invalid
- ng-dirty
- ng-pending
- ng-pristine
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="angular.min.js"></script>
<style>
input.ng-invalid {
background-color: lightblue;
}
</style>
</head>
<body>
<form ng-app="" name="myForm">
輸入你的名字:
<input name="myName" ng-model="myText" required>
</form>
<p>編輯文本域城舞,不同狀態(tài)背景顏色會發(fā)送變化伤靠。</p>
<p>文本域添加了 required 屬性媒至,該值是必須的,如果為空則是不合法的。</p>
</body>
</html>