我想要的是这样的: https://github.com/PatrickO10/meetUp
当你按下注册时,你会看到一些红色的音符。
他的代码在这里: https://github.com/PatrickO10/meetUp/blob/master/index.html#L95-L106 我试着自己写,但总是失败,不知道原因。我是这个领域的新手,你能帮我写一下吗?谢谢! 这是我测试这部分的简单代码: https://plnkr.co/edit/OL1QuesgZpqeEKoYS5cF?p=preview
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
</head>
<body>
<form name=signUpForm>
<label for="name">
<span>name:</span>
<input type="text" id="nameInput" name="nameInput" class="form-control" placeholder="your name" required autocomplete="name" autofocus ng-model="nameModel">
<div class="input-error" ng-message="signUpForm.nameInput.$error" role="alert" ng-if="signUpForm.nameInput.$touched">
<div ng-message="required">
<p>Input your name please!</p>
</div>
</div>
</label>
</form>
</body>
</html>
答案 0 :(得分:0)
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
</head>
<body ng-app="">
<form name=signUpForm novalidate ng-submit="signUp()">
<label for="nameInput">Name:</label>
<input type="text" id="nameInput" name="nameInput" class="form-control" placeholder="your name" ng-required="true" autocomplete="name" autofocus ng-model="nameModel">
<div ng-show="signUpForm.$submitted || signUpForm.nameInput.$touched">
<p style="color:red" ng-show="signUpForm.nameInput.$error.required">This field is required</p>
</div>
<button type="submit">Submit</button>
</form>
</body>
</html>
&#13;
您需要使用ng-app
初始化应用。
希望这个例子对你有帮助。