3

如果我在编辑后按回车键input_aprocessInputA()就会调用。该submit()功能被省略。

这不会发生input_b:即使它类似于 ,它也可以按预期工作input_a。该submit()函数按预期调用。

input_a触发后如何防止按钮?

<form class="uk-form" ng-submit="submit()">
  <div class="uk-form-row">
    <input type="text"
           name="input_a"
           ng-model="buffer.inputA" ng-change="reportInputATyped()"
           class="uk-width-3-10 uk-form-small">
    <button ng-cloak ng-show="inputADirty" class="uk-button uk-button-small" ng-click="processInputA()">Apply</button>
    /
    <input type="text"
           name="input_b"
           ng-model="buffer.inputB" ng-change="reportInputBTyped()"
           class="uk-width-6-10 uk-form-small">
    <button ng-cloak ng-show="inputBDirty" class="uk-button uk-button-small" ng-click="processInputB()">Apply</button>
  </div>
  // ...further inputs...
</form>

AngularJS:http ://angular-meteor.com

风格: http: //getuikit.com

4

1 回答 1

2

<button>submit如果通过 Chrome 呈现,元素似乎是默认类型。不是我直觉所期望的。

W4Schools.com 文章指出了提示:

始终指定元素的类型属性。不同的浏览器可能对元素使用不同的默认类型。

http://www.w3schools.com/tags/att_button_type.asp

如果由 Chrome 处理,则有效的版本:

<form class="uk-form" ng-submit="submit()">
  <div class="uk-form-row">
    <input type="text"
           name="input_a"
           ng-model="buffer.inputA" ng-change="reportInputATyped()"
           class="uk-width-3-10 uk-form-small">
    <button type="button" ng-cloak ng-show="inputADirty" class="uk-button uk-button-small" ng-click="processInputA()">Apply</button>
    /
    <input type="text"
           name="input_b"
           ng-model="buffer.inputB" ng-change="reportInputBTyped()"
           class="uk-width-6-10 uk-form-small">
    <button type="button" ng-cloak ng-show="inputBDirty" class="uk-button uk-button-small" ng-click="processInputB()">Apply</button>
  </div>
  // ...further inputs...
</form>
于 2015-08-24T15:13:57.363 回答