focusing on next input (jquery)

前端 未结 12 2426
慢半拍i
慢半拍i 2020-11-30 05:09

I\'ve got four inputs that each take one number. What I want to do is set the focus automatically to the next input once the number has been set. They all have the class \"i

12条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 05:27

    If you just want to look at the next input but you have say separators in the way like this

    
    
    /
    /

    You will need to you the this code to get all the next items and settle on the first input found:

    $('input#dobday,input#dobmonth,input#dobyear').on('input', function(e) {
        if (jQuery(this).val().length >= parseInt(jQuery(this).attr("maxlength"), 10)) {
                if (jQuery(this).attr('id') === 'dobyear') {
                    jQuery(this).blur();
                } else {
                    jQuery(this).nextAll('input:first').focus();
                }
        }
    }
    

提交回复
热议问题