I have an input which changes value when a click a button. What I want to do is to force an enter keyp开发者_如何学Goress event with jQuery. without pressing the button. Is this possible?
Thanks
jQuerys .trigger()
should do the trick:
$('input').trigger({
type: 'keypress',
which: 13
});
Ref.: .trigger()
$(element).keydown(function(event) {
if (event.keyCode == '13') {
event.preventDefault();
}
do_something();
});
I needed to use this on a search box to clear it's content...but instead of using 'keypress' or 'keydown', I needed to use 'keyup' so that the search function would fire also. This way I could clear the limiting search results.
精彩评论