我有以下html页面:
<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>
Run Code Online (Sandbox Code Playgroud)
现在我想总是跳到下一个输入字段.我试过了:
$("#birthdate input[type=text]").keyup(function(e){
if($(this).val().length == $(this).attr('maxlength')){
$(this).next(":input").focus();
}
});
Run Code Online (Sandbox Code Playgroud)
但这似乎仍然在场内.而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();
}
}
Run Code Online (Sandbox Code Playgroud)
我知道我也在我的主帖中添加了它,但这更容易收到评论。解决办法好像有很多。
目前我自己的解决方案:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
我试图保持它非常简单而灵活,我想我可能可以简化第二个,如果有的话。
| 归档时间: |
|
| 查看次数: |
2297 次 |
| 最近记录: |