|
<!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>指定文本框输入长度并自动转跳到下一个文本框</title> <meta http-equiv="content-type" content="text/html;charset=gb2312"> </head> <body> <!--把下面代码加到<body>与</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> |