How to Submit a Form on 'Enter' with jQuery
When working with login forms in an AIR project using HTML/jQuery, you may encounter an issue where pressing Enter clears the form's content instead of submitting it. To resolve this, ensure that your code properly handles this event.
The following code should accomplish this:
$('.input').keypress(function (e) { if (e.which == 13) { $('form#login').submit(); return false; //<---- Add this line } });
The key point here is adding the "return false" statement. This prevents the default action (clearing the form) from occurring while allowing the submit event to be triggered.
For more detailed information on this topic, refer to the stackoverflow answer on the subject of "event.preventDefault() vs. return false".
The above is the detailed content of How to Prevent Clearing Login Forms on Enter Keypress in jQuery?. For more information, please follow other related articles on the PHP Chinese website!