Posted in Javascript onDecember 23, 2014
<html> <head> <script type="text/javascript"> function moveNext(object,index){ if(object.value.length==4){ document.forms[0].elements[index+1].focus(); } } function showResult(){ var f=document.forms[0]; var result=""; for(var i=0;i<4;i++){ result+=f.elements[i].value; } alert(result); } </script> </head> <body onload="document.forms[0].elements[0].focus();"> <form> <input type="text" size="3" maxlength="4" onkeyup="moveNext(this,0);"> <input type="text" size="3" maxlength="4" onkeyup="moveNext(this,1);"> <input type="text" size="3" maxlength="4" onkeyup="moveNext(this,2);"> <input type="text" size="3" maxlength="4" onkeyup="moveNext(this,3);"> <input type="button" value="显示" onclick="showResult();"> </form> </body> </html>
代码很简单,功能非常实用,小伙伴们美化下就可以用到自己项目中了,是不是很炫酷
javascript实现依次输入input自动定焦
- Author -
hebedich声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@