Programmatically focus on next input field in mobile safari

后端 未结 6 1321
有刺的猬
有刺的猬 2020-11-27 04:26

I have several input fields in line that acts like a crossword answer line:

\"enter

6条回答
  •  余生分开走
    2020-11-27 04:51

    I hope this is what you are looking for-

    $(document).ready(function() {
      $('input:first').focus(); //focus first input element
    
      $('input').on('keyup', function(e) {
        if(e.keyCode == 8) {  //check if backspace is pressed
          $(this).prev('input').focus(); 
          return;
        }
        if($(this).val().length >= 1) { //for e.g. you are entering pin
          if ($(this).hasClass("last")) {
            alert("done");
            return;
          }
          $(this).next('input').focus(); 
        }
      });
    
      $('input').on('focus', function() {
        if(!$(this).prev('input').val()){
          $(this).prev('input').focus();
        }
      });
    });
    

    check code here-

    https://jsbin.com/soqubal/3/edit?html,output

提交回复
热议问题