js input框输入1位数字后自动跳到下一个input框聚焦

// input框输入1位数字后自动跳到下一个input聚焦
function goNextInput(el){
var txts = document.querySelectorAll(el);
for(var i = 0; i<txts.length;i++){
var t = txts[i];
t.index = i;
t.setAttribute("readonly", true);
t.onkeyup=function(){
this.value=this.value.replace(/^(.).*$/,'$1');
var next = this.index + 1;
if(next > txts.length - 1) return;
txts[next].removeAttribute("readonly");
if (this.value) {
txts[next].focus();
} }
}
txts[0].removeAttribute("readonly");
}

调用如下:goNextInput('.code-num');

上一篇:Understanding the Internal Message Buffers of Storm


下一篇:洛谷P1605走迷宫