我使用 Angular 和 Ionic 创建了一个混合应用,但是当我填写表单并按 GO 按钮或 Android 上的箭头按钮时,它会提交我的表单,即使它尚未生效。我尝试检测按键和 return:false;
但它仍然提交。
<form novalidate name="questionForm" id="questionForm" ng-submit="submit()">
<input name="question" ng-model="form.question" ng-minlength="10" required autofocus/>
<div id="answers">
<input ng-model="choice.choice" placeholder="Voeg antwoord toe" required ng-keypress="disableGo()" />
</div>
<button type="submit" ng-disabled="questionForm.$invalid" class="circle-btn btn-send ion-ios-paperplane"></button>
</form>
按键功能:
$scope.disableGo = function () {
var code = (event.keyCode ? event.keyCode : event.which);
if ((code == 13) || (code == 10)) {
return false;
}
};
最佳答案
Use
type='button'
instead ofsubmit
您不需要disableGo
试试这个:
<form novalidate name="questionForm" id="questionForm">
<input name="question" ng-model="form.question" ng-minlength="10" required autofocus/>
<div id="answers">
<input ng-model="choice.choice" placeholder="Voeg antwoord toe" required ng-keypress="disableGo()" />
</div>
<button type="button" ng-disabled="questionForm.$invalid" class="circle-btn btn-send ion-ios-paperplane" ng-click="submit()"></button>
</form>
在按钮
上使用ng-click
而不是ng-submit
关于javascript - “GO”按钮提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35198211/