focusing on next input (jquery)

前端 未结 12 2430
慢半拍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:29

    If you're using the latest jQuery version, I strongly recommend you to use the on method. If you go to the jQuery source code, you'll notice that all the other event methods now redirect to this method, so why don't use it directly:

    $(document).ready(function () {
            $('.inputs').on('keyup', function(){
                $(this).next().focus();
            })
    });
    

提交回复
热议问题