Automatically Move Cursor from One Textbox to Anot

2020-02-29 14:00发布

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

5条回答
男人必须洒脱
2楼-- · 2020-02-29 14:30

you can create a directive also to get the position move

<a href="https://plnkr.co/edit/G6sFMM9vaR6nQfVaMI2E?p=preview">directive 1</a>

<a href="https://plnkr.co/edit/G32KUITspNp1qsq6gleI?p=preview">directive 2</a>
查看更多
等我变得足够好
3楼-- · 2020-02-29 14:34

You can use JavaScript's Onchange Event (or JQuery may be) on the Textbox which calls a method, where You can check the value of the Textbox if it equals the Maximum value , then setFocus on the next Textbox.

查看更多
趁早两清
4楼-- · 2020-02-29 14:36

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">
查看更多
何必那么认真
5楼-- · 2020-02-29 14:43

Use the TextBox.Focus() method on the next TextBox. Use the first TextBox's TextBox.TextChanged event to test if focus should be changed and to call the Focus method on the next TextBox.

查看更多
家丑人穷心不美
6楼-- · 2020-02-29 14:48

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

Don't do that. Just use the Control.Focus() method.

When in HTML, you can use jQuery's focus():

$("#textbox").focus();
查看更多
登录 后发表回答