如何在单击表单字段以外的任何位置时触发表单字段上的按键?

时间:2014-02-04 01:53:32

标签: angularjs

我有一个表单字段,单击输入或按下保存字段保存。除了这个之外,我想要发生的是当用户点击页面上的任何其他位置时要保存的字段。

<input type="text" id="location" ng-model="location" ui-keypress="{enter: 'editLocation = !editLocation'}" class="ng-pristine ng-valid">

<a ng-click="editLocation = !editLocation" title="Click here or press the &quot;Enter&quot; key to save this edit.">
    <i class="icon-ok"> Save</i></a>

使用AngularJS实现这一目标的最佳方法是什么?

2 个答案:

答案 0 :(得分:0)

使用javascript中的“onBlur”事件? http://www.w3schools.com/jsref/event_onblur.asp

<input onBlur="myfunctionToSave()" ...>

答案 1 :(得分:0)

输入ngBlur。

http://docs.angularjs.org/api/ng.directive:ngBlur

<input ng-blur="saveStuffOnLeave()">
相关问题