jquery - How to simulate tab key with enter key on javascript - Stack Overflow

<script type="textjavascript">function onDataBound(e) {$("#batchgrid").on(&qu

    <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>

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.

please help me here..

    <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>

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.

please help me here..

Share Improve this question asked Jul 5, 2013 at 6:00 sanzysanzy 8159 gold badges18 silver badges28 bronze badges 1
  • did any of these proposed answers work for you? – rh4games Commented Oct 12, 2014 at 23:48
Add a ment  | 

2 Answers 2

Reset to default 1

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()
      }
    });
  });
}

It will not simulate until you prevent the default enter key event. event.preventDefault(); should be the first mand of your function.Then implement the tab key event.Your code should be something like this :

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

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

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

Hope it will work.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745300220a4621390.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信