【发布时间】: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()
有什么想法吗?谢谢
【问题讨论】:
-
.next 和 .nextAll 只选择兄弟姐妹,而不是堂兄弟。它在文档中。 api.jquery.com/nextall
标签: javascript jquery html input focus