开发者

Form won't reset after alert (when validated)

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜