Disable submit button ONLY after submit

前端 未结 13 627
囚心锁ツ
囚心锁ツ 2020-12-02 22:49

I have the following HTML and jquery:






Test disabling submit button fo

13条回答
  •  独厮守ぢ
    2020-12-02 23:28

    As a number of people have pointed out, disabling the submit button has some negative side effects (at least in Chrome it prevents the name/value of the button pressed from being submitted). My solution was to simply add an attribute to indicate that submit has been requested, and then check for the presence of this attribute on every submit. Because I'm using the submit function, this is only called after all HTML 5 validation is successful. Here is my code:

      $("form.myform").submit(function (e) {
        // Check if we have submitted before
        if ( $("#submit-btn").attr('attempted') == 'true' ) {
          //stop submitting the form because we have already clicked submit.
          e.preventDefault();
        }
        else {
          $("#submit-btn").attr("attempted", 'true');
        }
      });
    

提交回复
热议问题