// 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‘);
js input框输入1位数字后自动跳到下一个input框聚焦
原文地址:https://www.cnblogs.com/gopark/p/9357620.html