如何在javascript上使用enter键模拟tab键 [英] How to simulate tab key with enter key on javascript

查看:104
本文介绍了如何在javascript上使用enter键模拟tab键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    <script type="text/javascript">
        function onDataBound(e) {
            $("#batchgrid").on("click", "td", function (e) {

                $("input").on("keydown", function (event) {
                    if (event.keyCode == 13) {

                        event.keycode=9;
                        return event.keycode;
                    }
                });
            });
        }
    </script>

这里我使用上面的脚本来触发标签键按下事件我按下输入键。但是当我按下回车键时,它不会按下Tab键。

here i'm using above script to fire tab key press event when i press the enter key.but it doesn't behave as tab key pressed when i press the enter key.

请在这里帮助我。 。

推荐答案

return event.keycode 实际上是返回9 ,甚至返回事件也无济于事,因为返回事件并不意味着将会正确处理,你可能想要什么取而代之的是取输入事件,然后手动将焦点更改为下一个必填字段:

return event.keycode is effectively return 9, and even return event will not help, as returning the event does not mean that will be handled properly, what you probably want to do instead is to take the enter event and then manually change focus to the next required field:

function onDataBound(e) {
  $("#batchgrid").on("click", "td", function (e) {
    $("input").on("keydown", function (event) {
      event.preventDefault();
      if (event.keyCode == 13) {
        $(this).next("input, textarea").focus()
      }
    });
  });
}

这篇关于如何在javascript上使用enter键模拟tab键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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