jQuery: Stop submitting form, perform script, continue submitting form?

前端 未结 8 1042
遇见更好的自我
遇见更好的自我 2021-02-04 02:09

I have a form, and when I submit him I execute multiple script. Here is my code:

$(\"#RequestCreateForm\").submit(function (e) {
    if ($(\"#RequestCreateForm\"         


        
8条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 02:55

    Here is my approach to avoid the infinite loop.

    • In the form, I use a "button" with an id (e.g. ) to mimic the submit button;
    • In the script I have something like this:
    $('#submit').click(function() {
      if(//validation rules is ok)
      {
          $("#RequestCreateForm").submit(); //assuming the form id is #RequestCreateForm
      }
      else
      {
          return false;
      }
    });
    

提交回复
热议问题