使用javascript进行Autotab输入

时间:2013-04-05 19:52:30

标签: javascript

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

我的问题是,由于我的第二个输入已经有长度,它会跳转到第三个输入。如果使用缓慢输入值,则不执行此操作。

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

我已经写了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();
    });
}

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

0 个答案:

没有答案