• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

angularjs 在输入时焦点移动到下控件

用户头像
it1352
帮助1

问题说明

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

正确答案

#1

我建议制定一个自定义指令.像这样的东西.我还没有测试过.

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.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcajhgk
系列文章
更多 icon
同类精品
更多 icon
继续加载