Submitting a form on 'Enter' with jQuery?

后端 未结 14 1983
爱一瞬间的悲伤
爱一瞬间的悲伤 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:30

    You can also simply add onsubmit="return false" to the form code in the page to prevent the default behaviour.

    Then hook (.bind or .live) the form's submit event to any function with jQuery in the javascript file.

    Here's a sample code to help:

    HTML

    Javascript + jQuery

    $(document).ready(function() {
    
        $('#search_form').live("submit", function() {
            any_function()
        });
    });
    

    This is working as of 2011-04-13, with Firefox 4.0 and jQuery 1.4.3

提交回复
热议问题