问题是因为您没有阻止按钮单击的默认操作,因此页面重新加载使内容看起来像重新出现.试试这个:
或者更好的是,onclick
从HTML中删除过时的属性并使用JavaScript附加事件:
$(function() {
$('.btn-save').click(function(e) {
e.preventDefault();
var name = $('#name').val();
var surname = $('#surname').val();
if (name === "" && surname === "") {
alert("Please, enter your details!");
$("#UQ").hide();
}
else if(name !== "" && surname === "") {
alert("Please, enter your Surname");
$("#UQ").hide();
}
else if(name === "" && surname !== "") {
alert("Please, enter your Name");
$("#UQ").hide();
}
else {
$.post("saveDetails.php", {
name: name,
surname: surname
});
$("#detailsDiv").hide();
$("#UQ").show();
alert('You have been successfully registered!');
}
});
});