[英]Auto Tab to the next input field when 1 character is filled with an input field disabled
您好朋友,我想在填寫4個字符但1個字符並且如果有一個禁用的輸入字段傳遞到下一個啟用字段時將“自動”選項卡移到下一個輸入字段
你怎么這些問題? 填寫4個字符時自動跳至下一個輸入字段
<input class="inputs" type="text" maxlength="1" />
<input class="inputs" type="text" maxlength="1" />
<input class="inputs" type="text" maxlength="1" disabled="disabled" />
<input class="inputs" type="text" maxlength="1" />
<input class="inputs" type="text" maxlength="1" disabled="disabled" />
<input class="inputs" type="text" maxlength="1" />
$(".inputs").keyup(function () {
if (this.value.length == this.maxLength) {
$(this).next('.inputs').focus();
}
});
使用nextAll()
方法( next()方法不能使用,因為它僅選擇帶有:enabled
(僅獲取啟用的輸入)和:first
(獲得第一個或最接近的輸入)偽類選擇器的立即相鄰兄弟姐妹。
$(".inputs").keyup(function () {
if (this.value.length == this.maxLength) {
$(this).nextAll('.inputs:enabled:first').focus();
}
});
$(".inputs").keyup(function() { if (this.value.length == this.maxLength) { $(this).nextAll('.inputs:enabled:first').focus(); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input class="inputs" type="text" maxlength="1" /> <input class="inputs" type="text" maxlength="1" /> <input class="inputs" type="text" maxlength="1" disabled="disabled" /> <input class="inputs" type="text" maxlength="1" /> <input class="inputs" type="text" maxlength="1" disabled="disabled" /> <input class="inputs" type="text" maxlength="1" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.