首先嘿所有,
我正在尝试编写一个简单的焦点下一个脚本。这是我的javascript代码
var order = new function () {
this.fields = [
"#OrderViewModel_OrderCreditCartNumbers1",
"#OrderViewModel_OrderCreditCartNumbers2",
"#OrderViewModel_OrderCreditCartNumbers3",
"#OrderViewModel_OrderCreditCartNumbers4",
"#OrderViewModel_OrderCreditCartExpireMonthId",
"#OrderViewModel_OrderCreditCartExpireYearId",
"#CreditCardCustomerName",
"#OrderViewModel_OrderCreditCartCvc"
]
this.events = function () {
this.followcardnumber();
}
this.followcardnumber = function () {
for (var i = 0; i < 4; i++) {
var elem = $(this.fields[i]);
var nextelem = $(order.fields[i + 1]);
elem.on("keyup", function () {
if ($(this).val().length == 4 && i != 3) {
nextelem[0].focus();
}
});
}
}
}
$(document).ready(function () {
order.events();
});
此代码应跟踪前4个选择器的键盘事件并关注下一个选择器。问题是当字段完整脚本焦点字段[4]并且它应该聚焦下一个字段时。
任何提示?
感谢您的任何帮助或想法。