2011-08-23 57 views
1

我使用jQuery驗證插件,我也使用jQuery做了一個彈出窗口,我的形式是在一個封閉的動畫。自然的行爲jQuery的只有形式是有效

,我不想彈出窗口關閉,如果窗體無效並且錯誤需要修復。

這裏就是我的工作......

表單驗證:

$(document).ready(function(){ 
    $("#form").validate({ 
     errorContainer: "#messageBox1", 
     errorLabelContainer: "#messageBox1 ul", 
     wrapper: "li", 
    }); 
    }); 

提交表單按鈕動作:

$("#ContinueButton").click(function(){ 
$("#refer-a-friend").animate({ 
    top: "0%", 
    opacity: 0 
}, 500); 
}); 

那麼我將如何使它所以關閉動畫只有在表格有效時纔會觸發?

回答

1

當您提交#form時,您的驗證將運行。你#ContinueButton需要或者是type="submit",或致電$("#form").submit();

一旦你的按鈕提交射擊驗證,看看在documentationsubmitHandler選項,那應該是你所需要的。事情是這樣的:

$("#form").validate({ 
    submitHandler: function(form) { 
     //perform your animation here 
    } 
}); 
相關問題