使用jQuery将焦点设置到下一个输入字段
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用jQuery将焦点设置到下一个输入字段相关的知识,希望对你有一定的参考价值。
I was recently faced with the problem of setting focus to the next input field. The challenge was that I didn’t know what that field was. So given an input field, find the next logical (in the order of the DOM) input field and set focus. I came up with the following jQuery function (plugin) to accomplish this:
$.fn.focusNextInputField = function() { return this.each(function() { var fields = $(this).parents('form:eq(0),body').find('button,input,textarea,select'); var index = fields.index( this ); if ( index > -1 && ( index + 1 ) < fields.length ) { fields.eq( index + 1 ).focus(); } return false; }); };
以上是关于使用jQuery将焦点设置到下一个输入字段的主要内容,如果未能解决你的问题,请参考以下文章