How to trigger the enter keypress

前端 未结 3 1965
感情败类
感情败类 2020-12-08 14:50

I need to know how to trigger an enter key on an input. That is, in response to some other event (not a keypress), I need to trigger a keypress of value 13.

(Clarif

3条回答
  •  失恋的感觉
    2020-12-08 15:12

    You can do this -

    var e = $.Event( "keypress", { which: 13 } );
    $('#yourInput').trigger(e);
    
    • http://api.jquery.com/category/events/event-object/
    • http://api.jquery.com/trigger/

提交回复
热议问题