我有以下的HTML頁:的jQuery:選擇下一個輸入,即使在不同的字段集
<form action="editProfile" id="userInformation">
<fieldset id="birthdate">
<label><input type="text" id="day" maxlength="2"/>/<input type="text" id="month" maxlength="2"/>/<input type="text" id="year" maxlength="2"/>
</fieldset>
<fieldset>
<label>Name</label><input type="text" id="name"/>
</fieldset>
</div>
現在,我想一直跳到下一inputfield。 我已經試過:
$("#birthdate input[type=text]").keyup(function(e){
if($(this).val().length == $(this).attr('maxlength')){
$(this).next(":input").focus();
}
});
,但似乎停留在字段集內。而且nextall似乎沒有工作,或者我錯誤地使用它。
編輯: 我迄今爲止的解決方案:
if($(this).val().length == $(this).attr('maxlength')){
if($(this).parent().children().last().attr('id') == $(this).attr("id")){
$(this).parent().next().find(':input').focus();
}else{
$(this).next("input").focus();
}
}
我以前沒有遇到過這個問題;一個有趣的問題(和** + 1 **)=) – 2010-12-09 09:36:27
出於興趣,你爲什麼要在keydown處理程序中分配一個keydown處理程序? – Jamiec 2010-12-09 10:37:55