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

前端 未结 8 1049
遇见更好的自我
遇见更好的自我 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:56

    All solutions here are too complicated or lead to javascript error, simpliest and clearest solution I guess:

    jQuery("#formid").submit(function(e) {
            if( ! (/*check form*/)  ){  //notice the "!"
              e.preventDefault();
              //a bit of your code
            } //else do nothing, form will submit
    }); 
    

提交回复
热议问题