Submitting a form on 'Enter' with jQuery?

后端 未结 14 1973
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 14:45

I have a bog-standard login form - an email text field, a password field and a submit button on an AIR project that\'s using HTML/jQuery. When I hit Enter on the form, the

14条回答
  •  无人共我
    2020-11-22 15:13

    Don't know if it will help, but you can try simulating a submit button click, instead of directly submitting the form. I have the following code in production, and it works fine:

        $('.input').keypress(function(e) {
            if(e.which == 13) {
                jQuery(this).blur();
                jQuery('#submit').focus().click();
            }
        });
    

    Note: jQuery('#submit').focus() makes the button animate when enter is pressed.

提交回复
热议问题