gpt4 book ai didi

javascript - AngularJS 验证不起作用?

转载 作者:行者123 更新时间:2023-12-03 11:03:46 25 4
gpt4 key购买 nike

我是 AngularJS 的新手,我刚刚开始调整它附带的验证,但由于某种原因我无法让它们工作:

<div class="row">
<div class="col-xs-6">
<h2>Login</h2>
<p class="text-danger">{{message}}</p>
<form name="form" novalidate>
<label>Email: </label>
<input type="email" ng-model="credentials.email" placeholder="Email" class="form-control" required />
<label>Password: </label>
<input type="password" ng-model="credentials.password" placeholder="Password" class="form-control" />
<br />
<button class="btn btn-primary" ng-click="authenticate(credentials)">Login</button>
<a href="#/register">Register</a>
</form>
</div>
</div>

我命名了该表单并添加了 novalidate 。然后我尝试根据需要输入电子邮件,但将属性放在那里。但表单仍然会提交,并且 AngularJS 不会阻止它提交或显示任何警告。我错过了什么?

最佳答案

为您的输入提供名称字段

 <form name="form" novalidate>
<label>Email: </label>
<input type="email" name="email" ng-model="credentials.email" placeholder="Email" class="form-control" required />
<label>Password: </label>
<input type="password" ng-model="credentials.password" placeholder="Password" class="form-control" />
<br />
<button class="btn btn-primary" ng-disabled="form.$invalid" ng-click="authenticate(credentials)">Login</button>
<a href="#/register">Register</a>
</form>

这就是笨蛋:-) http://plnkr.co/edit/pAA2wBp8zgIZV6QLwO7S?p=preview

关于javascript - AngularJS 验证不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27958745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com