angularjs 在输入时将焦点移动到下一个控件 [英] angularjs move focus to next control on enter

查看:54
本文介绍了angularjs 在输入时将焦点移动到下一个控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最好的方法,当在表单内点击回车时,焦点转到下一个输入而不是使用 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();
        }
      });
    }
  }
});

这样的事情应该可行.你可能需要调整一些东西.祝你好运.

Something like that should work. You might have to tweek something. Good luck.

这篇关于angularjs 在输入时将焦点移动到下一个控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆