我正在使用jquery表單驗證插件來驗證我的表單。我已經設置了所有的規則,消息等。所以在我的html中,我做了一個css樣式的對話框,它僅僅作爲確認消息顯示給用戶。當用戶註冊這個div confirmation
時,只需在表單的動作文件被調用。我的問題是,我如何延遲表單提交操作的觸發時間足以讓我的確認淡入淡出。當我嘗試立即開始提交或完全沒有做任何事情。直到div動畫完成後延遲html表單提交
//validation plugin
$("#register_form").validate({
errorClass: "invalid",
invalidHandler: function (event, validator) {
$('html, body').animate({
scrollTop: '0px'
}, 300);
},
onfocusout: false,
onkeyup: false,
onclick: false,
rules: {
firstname: {
required: true
},
lastname: {
required: true
},
email: {
required: true,
email: true
}
},
messages: {
firstname: {
required: "Enter your first name"
},
lastname: {
required: "Enter your last name"
},
email: {
required: "Enter your email",
email: "Enter a valid email"
}
},
errorContainer: $(".errorCont"),
errorLabelContainer: $('.errorCont ul'),
wrapper: 'li',
}); //Etc above all working its the code below
$("#register_form").submit(function (e) {
e.preventDefault();
if ($("#register_form").valid()) {
showpopup();
// Show popup and then proceed with submission action ??
// calling submit here just submits straight away without waiting for pop to hide
}
});
function showpopup() {
$('#dialog').fadeIn("slow");
$("#bodywrap").css({
"opacity": "0.3"
});
setTimeout(hidepopup, 3000);
}
function hidepopup() {
$('#dialog').hide();
$("#bodywrap").css({
"opacity": "1");
}
}
我搞糊塗了。如果表單驗證成功,您是否希望等待動畫? – Itay
是的,在這一點上,我只是想...首先驗證表單。然後顯示確認3秒。然後執行由表單(php文件)指定的操作。之後,我會檢索表單值等等 – user1927602
我已經使用submitHandler,但是當我在尋找解決方案時,我注意到人們提到使用'.submit'。 – user1927602