jQuery - Cancel form submit (using “return false”?)?

后端 未结 12 1598
盖世英雄少女心
盖世英雄少女心 2020-12-19 04:00

I\'m running into a bit of trouble while trying to cancel the submit of a form. I\'ve been following this tutorial (even though i\'m not making a login script), and it seems

12条回答
  •  时光说笑
    2020-12-19 04:41

    I also had this problem, my code (that didn't work) was something like this:

    $('#upload_form').submit(function(){ before_submit('argument') });
    

    and inside the "before_submit" function i had "return false" to stop the form from submitting:

    function before_submit() {
    
    .........................................................
    return false;
    }
    

    I put "return" when binding the event handler function to the form and it worked:

    $('#upload_form').submit(function(){ return before_submit('argument') });
    

    The function attached to the submit event has to return false (in my case the anonymous function). So...this is one solution to one cause of this problem

提交回复
热议问题