Focus next input once reaching maxlength value

后端 未结 9 1177
梦毁少年i
梦毁少年i 2020-11-29 05:20

How can I focus the next input once the previous input has reached its maxlength value?

a: 
b: 

        
9条回答
  •  孤城傲影
    2020-11-29 05:49

    If you are adding input text fields dynamically then you can try this.

    This will re-inject the script into the DOM and works Perfectly.

    $('body').on('keyup', '#num_1',function(){
      if (this.value.length === parseInt(this.attributes["maxlength"].value)) {
        $('#num_2').focus();
      }
    })
    $('body').on('keyup','#num_2', function(){
       if (this.value.length === parseInt(this.attributes["maxlength"].value)) {
        $('#num_3').focus();
      }
    })
    
    
    

提交回复
热议问题