javascript - “GO”按钮提交表单

标签 javascript angularjs

我使用 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 of submit

您不需要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/

相关文章:

javascript - ng-mouseenter 的 Jasmine 测试

angularjs - 如何使用最新版本的 AngularJS 开始一个新项目?

javascript - 缩小 ASP.NET 生成的 Javascript 的最佳方法是什么?

javascript - 如何在 AngularJS 中通过 ID 从父 Controller 中选择选项

javascript - 在前端缓存动态生成的图像

javascript - Angular1.5 的哪个路由器?

javascript - Angular list 模型取消选中也会删除日期

javascript - map 不输出任何东西,没有错误信息

javascript - 尝试将数据从 Google 电子表格发布到外部 API

angularjs - 在不同模块中的指令和 Controller 之间共享数据