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

前端 未结 4 1756
耶瑟儿~
耶瑟儿~ 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:17

    Have you tried using

    $("input").trigger( 'keypress', e );

    as a solution?
    I find sometimes being explicit is best. If that doesn't work possibly even

    $("input").trigger( 'keypress', [{preventDefault:function(){},keyCode:9}] );.

    Hope this helps.

提交回复
热议问题