当文本框为空时如何向后聚焦

问题描述 投票:0回答:1

当当前文本框为空时,我想切换回上一个文本框。

当当前文本框已满时,我可以转到下一个文本框,但是当我删除文本框中的字符(长度== 0)时,我无法返回。

这是我的文本框:

<input id="txt_1" type="number" maxlength="3" onKeyDown="if(event.KeyCode != 8){if(this.value.length == 3){window.setTimeout(function (){document.getElementById('txt_2').focus();},0);return false;}}">
<input id="txt_2" type="number" maxlength="3" onKeyDown="if(event.KeyCode != 8){if(this.value.length == 3){window.setTimeout(function (){document.getElementById('txt_3').focus();},0);return false;}}">
<input id="txt_3" type="number" maxlength="3" onKeyDown="if(event.KeyCode != 8){if(this.value.length == 3){return false;}}">

我可以去(灌装时):

txt_1 > txt_2 > txt_3

我无法返回(删除时),例如:

txt_3 > txt_2 > txt_1
javascript jquery focus onkeydown backspace
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.