2

私はこのhtmlを持っています:

        <div class="field phone">
            <input type="text" maxlength="3" />
        </div>
        <div class="field phone number1">
            <input type="text" maxlength="3" />
        </div>
        <div class="field phone number2">
            <input type="text" maxlength="4" />
        </div>

それから私は使用しています

    $(".phone input:not(:last)").keydown(function() {
        var that = this;
        setTimeout(function() {
            if (that.prevValue != $(that).val()) {
                that.prevValue = $(that).val();
                if ($(that).val().length == $(that).attr("maxlength")) {
                    $(that).nextAll("input")[0].focus();
                }
            }
        });
    });

問題は$(that).nextAll("input")[0]、入力セレクターの代わりに未定義を返し、それを使用できfocus()ないことです

ここで何が起こっているのかアイデアはありますか?ありがとう

4

1 に答える 1

3

置き換えることができます:

$(that).nextAll("input")[0].focus();

のようなもので

$(that).parent().next(".phone").find("input").focus();

Kevin Bが言ったように、.nextそして.nextAll兄弟だけに取り組むので、あなたは親に戻って、親の兄弟に、そして次に子供に戻る必要があります。

于 2013-01-11T19:28:42.470 に答える