Javascript 在角度输入字段中输入时触发功能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27041064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 23:38:46 来源:igfitidea点击:
Trigger function on enter in angular input field
提问by orikoko
is there a way to trigger event when clicking on ENTER key in the input field? I found a directive that someone suggested to use, but I wonder if there is a simple way to do it.
单击输入字段中的 ENTER 键时,有没有办法触发事件?我找到了有人建议使用的指令,但我想知道是否有一种简单的方法可以做到。
I am using angular 1.3.
我正在使用角度 1.3。
回答by Neeraj Dubey
$timeout(function() {
angular.element('#myselector').trigger('click');
}, 100);
If you want trigger on press on enterkey you need to write like that
如果你想在按键时触发,enter你需要这样写
<input ng-keyup="$event.keyCode == 13 ? myFunc() : null">

