[英]Hide Form when submit
I have the following function: 我有以下功能:
var form = $('#review-contact-form');
form.submit(function(event){
event.preventDefault();
var form_status = $('<div class="form_status center"></div>');
$.ajax({
type: "POST",
url: $(this).attr('action'),
data: form.serialize(),
beforeSend: function(){
form.prepend(
form_status
.html('<p><i class="fa fa-spinner fa-spin"></i> Sending...</p>')
.fadeIn()
);
}
}).done(function(data){
form_status
.html('<p class="text-success">Thanks!</p>')
.delay(3000)
.fadeOut();
});
});
Is there a way to hide the form when mail is sent? 发送邮件时是否可以隐藏表格?
form.hide();
after your form_status
in done
function. 在done
功能的form_status
之后。
NOTE: I added this as answer because I cannot add comments 注意:我将其添加为答案,因为我无法添加评论
You can use fadeOut()
on the form
too in the done
promise: 您也可以在已done
诺言中在form
上使用fadeOut()
:
var form = $('#review-contact-form');
form.submit(function(event) {
event.preventDefault();
var form_status = $('<div class="form_status center"></div>');
$.ajax({
type: "POST",
url: $(this).attr('action'),
data: form.serialize(),
beforeSend: function() {
form.prepend(
form_status
.html('<p><i class="fa fa-spinner fa-spin"></i> Sending...</p>')
.fadeIn()
);
}
}).done(function(data) {
form.fadeOut();
form_status
.html('<p class="text-success">Thanks!</p>')
.delay(3000)
.fadeOut();
});
});
Also, if you have the .form_status
and .text-success
elements inside the form move it outside of it, otherwise you won't be able to see the message when the form submit is done. 另外,如果表单内有.form_status
和.text-success
元素,则将其.form_status
表单,否则在表单提交完成后,您将看不到该消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.