Passcoder 是我制作并将发布的 jquery 库。它将输入字段拆分为一个字符的输入框(如 iPhone 密码)。它的功能之一是按下一个按钮来聚焦下一个输入。
问题似乎是.next('.passcoder')
没有做预期的事情。在输入的第一行(employee_name 输入)上,它将按预期运行,但是当它应该关注第一个密码输入(从第四个员工姓名到密码)时,.next('.passcoder')
它不会返回任何内容。
标记:
<form action="" method="post"
<h4>Employee Number</h4>
<input type="text" class="single-character-name passcoder" name="employee_number-0">
<input type="text" class="single-character-name passcoder" name="employee_number-1">
<input type="text" class="single-character-name passcoder" name="employee_number-2">
<input type="text" class="single-character-name passcoder" name="employee_number-3">
<br>
<h4>Employee Passcode</h4>
<input type="password" class="single-character-password passcoder" name="employee_passcode-0">
<input type="password" class="single-character-password passcoder" name="employee_passcode-1">
<input type="password" class="single-character-password passcoder" name="employee_passcode-2">
<input type="password" class="single-character-password passcoder" name="employee_passcode-3">
<br />
<br />
<input class="btn btn-success" type="submit">
<a class="btn">Cancel</a>
</form>
javascript (jQuery):
$('.passcoder').keyup(function(e){
if (e.which == 8){
//backspace
$(this).prev('input').focus();
}
else if(e.which > 47 && e.which < 58){
$(this).next('.passcoder').focus();
}
else{
$(this).val('');
return false;
}
});