陪你做好前端设计!
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>素材8网教程(study.sucai8.cn)</title> </head> <body> <p>在文本域达到最大字符时自动跳到下一个文本域:</p> <form id="myForm"> <input type="text" size="3" tabindex="1" maxlength="3" onkeyup="myFunction(this,this.value)"> - <input type="text" size="2" tabindex="2" maxlength="2" onkeyup="myFunction(this,this.value)"> - <input type="text" size="3" tabindex="3" maxlength="3" onkeyup="myFunction(this,this.value)"> </form> <script> function myFunction(x, y) { if (y.length == x.maxLength) { var next = x.tabIndex; if (next < document.getElementById("myForm").length) { document.getElementById("myForm").elements[next].focus(); } } } </script> </body> </html>
运行结果