5
我已经看到HTML表单,光标从一个输入字段自动移动到另一个输入字段,并使用退格移动到前一个字段。在需要粘贴跨越多个输入字段的序列号或者像在多个字段输入中输入的键入或粘贴号码的情况下,这很有用。聚焦nextlength/prev输入maxlength达到或退格按键
$(document).ready(function() {
$('.Box').on("keyup", function(e) {
var Length = $(this).attr("maxlength");
if ($(this).val().length >= parseInt(Length)) {
$(this).removeClass("productkey1").addClass("productkey2");
$(this).next('.Box').focus();
}
});
});
$(document).ready(function() {
$('.Box').on("keydown", function(e) {
var Length = $(this).attr("maxlength");
if ($(this).val().length > parseInt(Length)) {
$(this).removeClass("productkey2").addClass("productkey1");
$(this).prev('.Box').focus();
}
});
});
.Box:focus {
border: thin solid #FFD633;
-webkit-box-shadow: 0px 0px 3px #F7BB2E;
-moz-box-shadow: 0px 0px 3px #F7BB2E;
box-shadow: 0px 0px 3px #F7BB2E;
}
.Box {
height: 15px;
width: 4%;
text-align: justify;
letter-spacing: 5px;
padding: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div>
<sapn>Enter Key Code :</sapn>
<input class="Box productkey1" style="width: 35px;" type="password" name="number1" maxlength="1">
<input class="Box productkey1" style="width: 35px;" type="password" name="number2" maxlength="1">
<input class="Box productkey1" style="width: 35px;" type="password" name="number3" maxlength="1">
<input class="Box productkey1" style="width: 35px;" type="password" name="number4" maxlength="1">
</div>
太棒了!每个领域接受4个字母? – M98
谢谢,,,它的工作 – sridharan