angularjs将焦点移到上输入下一个控制 [英] angularjs move focus to next control on enter
问题描述
什么是最好的方式,创下了形式进入里面时,焦点转到下一个输入,而不是提交与angularjs形式。
What is the best way, when hitting enter inside a form, the focus to go to the next input instead submitting the form with angularjs.
我有很多领域和客户的一种形式,是用来打ENTER移动到下一个输入(从桌面应用程序正在添加)。该angularjs节省当用户点击进入形式。我想改变这一点。这可能吗?
I have a form with a lot of fields and customers are used to hit enter to move to the next input (comming from desktop applications). The angularjs saves the form when the user hits enter. I like to change this. Is it possible ?
推荐答案
我建议制作一个自定义的指令。事情是这样的。我没有测试过这一点。
I suggest making a custom directive. Something like this. I haven't tested this.
.directive('focus', function() {
return {
restrict: 'A',
link: function($scope,elem,attrs) {
elem.bind('keydown', function(e) {
var code = e.keyCode || e.which;
if (code === 13) {
e.preventDefault();
elem.next().focus();
}
});
}
}
});
这样的东西应该工作。您可能需要tweek的东西。祝你好运。
Something like that should work. You might have to tweek something. Good luck.
这篇关于angularjs将焦点移到上输入下一个控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!