I have a basic form
with a search input
and a submit button
within. When focus takes place in the input
, the keyboard is displayed as expected. When I press the button
, the form submit event occurs, in which I call event.preventDefault()
and instead make an ajax call. However, when I press the search button on the keyboard, the keyboard just hides and no submit event occurs.
Why doesn't the form submit when I press search on the keyboard? How can I trigger this event to happen via the keyboard search button?
Thanks.
The keyboard search button must be bound to a keypress event and has the keycode
of 13
.
Basically, listen to keypress
events and return all calls except for e.which === 13
$('input').on('keypress', function ( e ) {
if ( e.which !== 13 ) {
return;
}
// ajax code
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.