jQuery Mobile在keypress上关注下一个输入

use*_*175 9 focus input tap jquery-mobile

我有一个jquery移动网站,其中包含一个由4个引脚输入框组成的html表单.我希望用户能够在每个输入字段中输入一个引脚而无需按下iphone键盘"下一步"按钮.我曾尝试以下,虽然它似乎将焦点设置到第二输入和插入值时,键盘会消失,因此用户仍然具有激活与轻敲事件所需的输入.

$('#txtPin1').keypress(function() {
        $('#txtPin1').bind('change', function(){  
            $("#txtPin1").val($("#txtPin1").val()); 
        });
        $("#txtPin2").focus();
        $("#txtPin2").val('pin2');
});
Run Code Online (Sandbox Code Playgroud)

是否有一个不同的事件,我应该分配给$("#txtPin2")?

我也尝试过实现http://jqueryminute.com/set-focus-to-the-next-input-field-with-jquery/,但我发现它适用于android而不适用于iphone.

任何帮助都非常感激.

Phi*_*ord 4

实例: http: //jsfiddle.net/Q3Ap8/22/

JS:

$('.txtPin').keypress(function() {
    var value = $(this).val();

    // Let's say it's a four digit pin number
    // Value starts at zero
    if(value.length >= 3) {
        var inputs = $(this).closest('form').find(':input');
        inputs.eq( inputs.index(this)+ 1 ).focus();
    }
});
Run Code Online (Sandbox Code Playgroud)

HTML:

<div data-role="page" data-theme="b" id="jqm-home">
    <div data-role="content">
        <form id="autoTab">
            <label for="name">Text Pin #1:</label>
            <input type="text" name="txtPin1" id="txtPin1" value="" class="txtPin" placeholder="Please enter Pin #1"/>

            <br />
            <label for="name">Text Pin #2:</label>
            <input type="text" name="txtPin2" id="txtPin2" value="" class="txtPin" placeholder="Please enter Pin #2"/>

            <br />
            <label for="name">Text Pin #3:</label>
            <input type="text" name="txtPin3" id="txtPin3" value="" class="txtPin" placeholder="Please enter Pin #3"/>

            <br />
            <label for="name">Text Pin #4:</label>
            <input type="text" name="txtPin4" id="txtPin4" value="" class="txtPin" placeholder="Please enter Pin #4" maxlength="4"/>
        </form>
    </div>
</div> 
Run Code Online (Sandbox Code Playgroud)