Jquery prevent multiple submit

后端 未结 7 832
花落未央
花落未央 2020-12-30 09:58

I want to prevent multiple submit if someone click on one of the submit buttons multiple times.

How can unbind or undelgate in this case th

相关标签:
7条回答
  • 2020-12-30 10:46

    Bind and unbind are deprecated in JQuery.

    As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document.

    http://api.jquery.com/on/

    To answer your question about multiple submits, another new addition in JQuery 1.7 is the .one() handler which, attaches an event handler to an object but only allows it to be fired once. This will allow you to prevent multiple submits.

    e.g:

    $("form#form1").one("submit", submitFormFunction);
    
    function submitFormFunction(event) {
        event.preventDefault(); 
        $("form#form1").submit();
    }
    

    Note I'm binding to the form submit event rather than a button click event.

    0 讨论(0)
提交回复
热议问题