Type a word from the keyboard and store each letter into a series of multiple input text boxes

后端 未结 2 611
夕颜
夕颜 2021-01-22 03:47

I would like to present to the user several input text box that allows them to type a string of letters or characters that stores one letter into each box in a \'sp

2条回答
  •  天涯浪人
    2021-01-22 04:44

    If you need a jquery solution, than you can use .keyup() event, and an if condition, which will check the length of the input filed, if it exceeds 1, it will focus the very next field.

    Demo

    $("input").keyup(function() {
        if($(this).val().length >= 1) {
          var input_flds = $(this).closest('form').find(':input');
          input_flds.eq(input_flds.index(this) + 1).focus();
        }
    });
    

    Make sure you also use maxlength attribute on your input fields, so that a user typing fast may not exceed the character limit.

    Demo 2

提交回复
热议问题