自动将光标从一个文本框移动到另一个文本框

问题描述:

我正在制作验证密码的Web应用程序,并显示一些值,输入的文件有四个密码验证密码,我输入密码,就像我们在支付网关中输入信用卡号一样。在我目前的应用程序中,我输入了一个密码,然后按Tab或使用鼠标我必须选择下一个文本框输入下一个密码,如何使鼠标光标自动从一个文本框跳转到另一个文本框,在其最大值填充像支付网关

I am making a Web application that validates passkeys and displays some values there are four passkeys for a file to be entered Validate it, I am entering the passkeys just like we enter the Credit Card Number in the Payment gateway. In my present application I have enter one Passkey then have to press Tab or using the Mouse I have to select the Next Textbox to enter next Passkey, How do I Make the mouse Cursor to Jump automatically from one Textbox to Another Textbox after its maximum value filled like in Payment gateways

您可以像这样做纯JavaScript:

You can do pure javascript like this:

<script type="text/javascript">
function ValidatePassKey(tb) {
  if (tb.TextLength >= 4)
    document.getElementById(tb.id + 1).focus();
  }
}
</script>

<input id="1" type="text" onchange="ValidatePassKey(this)" maxlength="4">
<input id="2" type="text" onchange="ValidatePassKey(this)" maxlength="4">
<input id="3" type="text" onchange="ValidatePassKey(this)" maxlength="4">
<input id="4" type="text" maxlength="4">