How can I automatically tab to the next field using jQuery?

前端 未结 4 1732
耶瑟儿~
耶瑟儿~ 2021-01-12 12:42

In jQuery, how can I trigger the behavior of a user tabbing to the next input field?

I\'ve tried this:

var e = jQuery.Event(\"keydown\");
e.which = 9         


        
4条回答
  •  执念已碎
    2021-01-12 13:09

    See the accepted answer to this question. If for example you want to move focus to the next field when a certain number of characters have been entered, you could use that code in the keyup event, and check the entered number of characters.

    The code in that answer works by getting the set of inputs in the form, finding the selected input and adding 1 to the index of the selected input, and then triggering the focus event on the element with that index.

提交回复
热议问题