【发布时间】:2017-05-10 14:09:20
【问题描述】:
Codepen 链接:http://codepen.io/anon/pen/mVyPaw
需要创建一个 Angular 应用程序(带 1 个控制器)来验证此表单是否已填写所有三个字段,并且只有在表单有效时才能启用提交按钮。不需要使用预处理器。
<div class="container" ng-app="myApp" ng-controller="formCtrl">
<h1><span><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/15309/angular-logo.svg" alt="Angular.js Logo" /></span> Angular.js - Web Form</h1>
<form role="form" name="form" id="contact-form">
<div class="form-group">
<label for="FirstName">First name</label>
<input type="text" class="form-control" name="FirstName" id="FirstName" placeholder="enter first name" ng-model="firstName">
</div>
<div class="form-group">
<label for="LastName">Last Name</label>
<input type="text" class="form-control" name="LastName" id="LastName" placeholder="enter last name" ng-model="lastName">
</div>
<div class="form-group">
<label for="EmailAddress">Email address</label>
<input type="email" class="form-control" id="EmailAddress" name="EmailAddress" placeholder="enter email" ng-model="emailAddress" ng-model-options="{ updateOn: 'blur' }">
</div>
<div class="checkbox">
<label>
<input type="checkbox" required> Check me out
</label>
</div>
<button type="submit" class="btn btn-default" ng-model="submitButton">Submit</button>
</form>
</div>
【问题讨论】:
-
您尝试使用验证吗?
-
查看我的更新答案
-
我对 Angular 有点陌生,所以不知道该怎么做
标签: angularjs