开发者

Form won't reset after alert (when validated)

开发者 https://www.devze.com 2023-03-11 09:35 出处:网络
I validate my form with jquery validate and everything goes fine. What won\'t work is that, after successfully validating I want it to send an alert and clear the form. The alert will pop but the form

I validate my form with jquery validate and everything goes fine. What won't work is that, after successfully validating I want it to send an alert and clear the form. The alert will pop but the form won't reset. I can make it reset if I don't have the alert, but both won't work at the same time:

 $(document).ready(function() {
 var validator = $("#contacto").validate({
    errorLabelContainer: "#messageBox",
    wrapper: "li",
    submitHandler: function() { alert("Formulario enviado") }
 })
 validator.resetForm();

 })开发者_运维技巧;


            $(document).ready(function() {
         var validator = $("#contacto").validate({
            errorLabelContainer: "#messageBox",
            wrapper: "li",
            submitHandler: function() { alert("Formulario enviado");
 validator.resetForm();
    $("#contacto")[0].reset(); 
         }
         })

         });

your reset call was outside. so it will be only call once after page load.


Why not:

submitHandler: function( form ) { alert("Formulario enviado"); $(form).reset();
 }

?

0

精彩评论

暂无评论...
验证码 换一张
取 消