【发布时间】:2026-01-08 00:00:01
【问题描述】:
我创建了一个包含六个字段的表单,其中五个是必填字段。有一个提交按钮。如果用户没有在文本框中输入任何内容并单击提交按钮,则所有必需的文本框都应以红色边框突出显示。如何实施? :-
<div ng-app="myApp" ng-controller="formCtrl">
<form name="demoForm">
<label>First Name :</label>
<input type="text" ng-model="firstName" required/><br><br>
<label>Last Name :</label>
<input type="text" ng-model="lastName"/><br><br>
<label>Email :</label>
<input type="email" ng-model="emailDet" required/><br><br>
<label>Contact No :</label>
<input type="text" ng-model="contactNo" required/><br><br>
<label>Current Location :</label>
<input type="text" ng-model="currLoc" required/><br><br>
<label>Preferred Location :</label>
<input type="text" ng-model="preLoc" required/><br><br>
<button type="button" ng-click="onSubmit()">Submit</button>
</form>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('formCtrl', function($scope) {
$scope.onSubmit = function() {
}
});
</script>
【问题讨论】:
-
欢迎来到 *。请查看How to Ask,然后编辑您的问题以显示您尝试过的内容并描述无效的内容。
标签: angularjs