Move Cursor to next text Field pressing Enter

前端 未结 5 1290
半阙折子戏
半阙折子戏 2020-12-24 09:30

I have multiple text fields in my form and I want when user enters data in one text field and press enter that the cursor moves to another text-field which is next to curren

5条回答
  •  自闭症患者
    2020-12-24 09:53

    $("input").keypress(function(e) {
      if (e.which == 13) {
        var index = $("input[type='text']").index(this);
        $("input[type='text']").eq(index + 1).focus();
        e.preventDefault();
      }
    });
    

    It worked perfectly for me and supports almost every jquery versions!

提交回复
热议问题