1

当达到最大长度时,我有 3 个输入需要跳到下一个。这 3 个输入带有值,当用户更改第一个输入的值时,它会关注下一个输入,依此类推。

我的问题是,由于我的第二个输入已经具有跳到第三个输入的长度。如果用户缓慢输入值,则不会这样做。

问题的根源在于,如果输入速度太快,第一个 keyup 事件会在第二个类型之后触发,并在第二个输入上触发。

我已经为这个问题写了一个jsfiddle,这是我连接自动焦点更改的函数。

 function WireAutoTab(CurrentElement, NextElement) {
    CurrentElement.keyup(function (e) {
        //Retrieve which key was pressed.
        var KeyID = (window.event) ? event.keyCode : e.keyCode;
        var FieldLength = CurrentElement.attr('maxlength');

        //If the user has filled the textbox to the given length and
        //the user just pressed a number or letter, then move the
        //cursor to the next element in the tab sequence.   
        if (CurrentElement.val().length >= FieldLength && ((KeyID >= 48 && KeyID <= 90) || (KeyID >= 96 && KeyID <= 105)))
            NextElement.focus();
    });
}

是否有任何其他事件可以用来防止这种情况发生?我想要的行为是,即使第二个输入有值,它也会停止。

4

0 回答 0