jQuery simulate to press enter

2019-09-17 03:10发布

问题:

Hello I am trying to simulate pressing enter in an input box I been trying with:

 var e = $.Event('keypress');
 e.which = 13;         
 $('#inputdId').trigger (e);

But it didn't work out. Where is the mistake?

Thanks

回答1:

I found a way:

var e = jQuery.Event( 'keydown', { which: 13 } ); jQuery('input').trigger(e);