假设我提交表单,它会给我一个错误或成功消息。我关闭模态,如果我再次单击打开它,消息仍然存在。我该如何清除它?
$("#JqAjaxForm").submit(function(e){
e.preventDefault();
dataString = $("#JqAjaxForm").serialize();
$.ajax({
type: "POST",
url: "update.php",
data: dataString,
dataType: "json",
success: function(data) {
//clearForm("#JqAjaxForm");
if(data.email_check == "invalid"){
$("#message_ajax").html("<p class='alert alert-error'>Sorry " + data.name + ", " + data.email + " is NOT a valid e-mail address. Try again.</p>");
} else {
$("#message_ajax").html("<p class='alert alert-success'>" + data.newpasswd + " is a valid e-mail address. Thank you, " + data.name + ".</p>");
}
}
});
});
$('#chg_settings').modal({
backdrop: 'static',
keyboard: true,
show: false
});
我通过
调用模态<a data-toggle="modal" href="#chg_settings">Settings</a>
这是消息div
<div id="message_ajax"></div>
答案 0 :(得分:2)
您可以注册这样的hidden
事件
$('#chg_settings').on('hidden', function () {
$("#message_ajax").html('');
})
当模态完成对用户的隐藏时将触发此事件(将等待css转换完成)。