Focus next input once reaching maxlength value

后端 未结 9 1182
梦毁少年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:45

    let otp = document.querySelector('#otp-screen');
    
    for(let pin of otp.children) {
        pin.onkeyup = function() {
            if(pin.nextElementSibling) {
                pin.nextElementSibling.focus();
            }
        }
    }

提交回复
热议问题