Gui*_*rmo 13 html javascript validation angularjs
给出一个像这样的简单html表单:
<form name="myForm" action="#sent" method="post" ng-app>
<input name="userPreference1" type="text" ng-model="shipment.userPreference" />
<input name="userPreference1" type="text" ng-model="shipment.userPreference" />
<input name="userPreference1" type="text" ng-model="shipment.userPreference" />
... submit input and all the other code...
</form>
Run Code Online (Sandbox Code Playgroud)
如果至少有一个输入是空的,我需要你的帮助才能知道如何检查验证时间.所需的验证如下.用户必须至少完成一个偏好.
使用jQuery:
if ( $("input").val() == "" ) {
Run Code Online (Sandbox Code Playgroud)
工作正常,但想知道如何使用角度做同样的事情.
非常感谢,提前,
吉列尔莫
zs2*_*020 29
因此,如果所有输入都为空,则禁用提交按钮.你可以这样做
<form name="myForm" action="#sent" method="post" ng-app>
<input name="userPreference1" type="text" ng-model="shipment.userPreference1" />
<input name="userPreference1" type="text" ng-model="shipment.userPreference2" />
<input name="userPreference1" type="text" ng-model="shipment.userPreference3" />
<button type="submit" ng-disabled="!(!!shipment.userPreference1 || !!shipment.userPreference2 || !!shipment.userPreference3)">Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud)
!!str
是强制转换str
为一个boolean
值.两者!!null
和!!""
被评估为false
.
归档时间: |
|
查看次数: |
25737 次 |
最近记录: |