BootWiki教程网
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>BootWiki 教程网</title> </head> <body> <p>在文本域达到最大字符时自动跳到下一个文本域:</p> <form id="myForm"> <input maxlength="3" onkeyup="myFunction(this,this.value)" size="3" tabindex="1" type="text"> - <input maxlength="2" onkeyup="myFunction(this,this.value)" size="2" tabindex="2" type="text"> - <input maxlength="3" onkeyup="myFunction(this,this.value)" size="3" tabindex="3" type="text"> </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>
运行结果