【问题标题】:how to use nextAll to find all inputs using jquery/如何使用 nextAll 使用 jquery/ 查找所有输入
【发布时间】:2013-01-11 19:20:08
【问题描述】:

我有这个 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()

有什么想法吗?谢谢

【问题讨论】:

标签: javascript jquery html input focus


【解决方案1】:

你可以替换:

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

类似的东西

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

正如 Kevin B 所说,.next.nextAll 仅适用于兄弟姐妹,因此您需要返回到父级,再到父级的兄弟姐妹,然后再到子级。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    • 2010-09-17
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多