[英]Jquery autofocus on next field
2位数字后我如何在下一个字段上自动对焦?
这是对我不起作用的jQuery-
$("#personalDetailMobilePhoneAreaInput").keyup(function () {
if (this.value.length == this.maxLength) {
$(this).next(':input').focus();
}
});
@Html.TextBoxFor(m => m.CommunicationView.MobilePhone.Area, new { @id = "personalDetailMobilePhoneAreaInput", @class="customText wdt80 numericValue",type = "text",maxlength="2" })
@Html.ValidationMessageFor(m => m.CommunicationView.MobilePhone.Area)
@Html.TextBoxFor(m => m.CommunicationView.MobilePhone.Number, new { @id = "personalDetailMobilePhoneNumberInput", @class="customText wdt120 mrglft10 phnIE numericValue",type = "text",maxlength="8" })
@Html.ValidationMessageFor(m => m.CommunicationView.MobilePhone.Number)
尝试这个:
$('#personalDetailMobilePhoneAreaInput').keyup(function(){
var maxLength = $(this).attr('maxlength');
var currLength = $(this).val().length;
if(currLength >= maxLength)
$(this).siblings('input').focus();
});
自己尝试: http : //jsfiddle.net/4kjh44Lm/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.