在我的主ng-controller
中,我想将所有输入绑定(bind)到焦点事件并触发一个函数。到目前为止我尝试过(但失败了)的是:
// This makes sense since it is not a bind
$('input').focus(function(){});
// This should work, but doesn't!
$('input').bind('focus', function() {});
我有什么选择?如何将所有输入
绑定(bind)到焦点?
最佳答案
您可以将 ngFocus 指令添加到所有输入字段: https://docs.angularjs.org/api/ng/directive/ngFocus
<input type="text" ng-focus="controllerFunction()"></input>
或者阅读这个答案,了解如何对所有输入全局执行此操作: AngularJS: extend input directive
关于javascript - AngularJS - 将输入绑定(bind)到焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24905669/