简单教程
提交运行
代码编辑器:
<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>
运行结果: