[英]Focus on next input element by refer class name using jquery
當用戶在文本框中輸入值時,如果該輸入字段包含特定的類名,則應移至下一個文本框,但如果另一個文本框沒有該類名,則不應移至下一個
<input type="text" maxlength="1" class="txt_cls" />
<input type="text" maxlength="1" class="txt_cls" />
<input type="text" maxlength="1" class="txt_cls" />
<input type="text" maxlength="1" class="" />
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script>
$(document).ready(function(){
$('input.txt_cls').on("input", function(){
if($(this).val().length==$(this).attr("maxlength")){
// $(this).next().focus();
$(this).next().find('.txt_cls').focus();
}
});
});
</script>
哦,我犯了一個小錯誤,忘了提到 .closest(); 現在它工作正常
$(document).ready(function(){
$('input.txt_cls').on("input", function(){
if($(this).val().length==$(this).attr("maxlength")){
//$(this).next().focus();
$(this).next().closest('.txt_cls').focus();
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.