This article describes the method of JS to automatically jump to the next text box after exceeding the length limit. Share it for your reference. The specific implementation method is as follows:
Copy the code as follows:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JS control automatically jumps to the next text box after exceeding the length limit</title>
</head>
<body>
<input type="text" size="10">
<input type="text" size="10">
<input type="text" size="10">
<script language="javascript">
function Each(arr,fn){for(var i=0,len=arr.length;i<len;i++){fn.call(arr[i],i,arr);};};
(function(inputs){
Each(inputs,function(i){
var _o=this;
this.onkeyup=function(){
if(_o.value.length>=4){
if(inputs[i+1]){
inputs[i+1].focus();
}else{
_o.value=_o.value.slice(0,4);
}
}
}
})
})(document.getElementsByTagName('input'));
</script>
</body>
</html>
I hope this article will be helpful to everyone's JavaScript programming.