一个暂存一个发布,只是状态一不一样,需要带上表单内部元素的value,只能通过submit()方法,需要动态给action附参数。
代码片段如下。
<form method="post" id="newblog">
<button id="publish" type="button">发布文章</button>
<button id="tempsave" type="button">暂存</button>
</form>
$("#publish").on('click', function() {
if (checklogin() && checktitle() && checkcontent() && checkcode()) {
sweetAlert({
title : "您的文章已发布 !",
text : "Your blog has been published.",
type : "success"
}, function() {
document.getElementById("newblog").action=".newBlogServlet?state=1";
document.getElementById("newblog").submit();;
});
} else {
return false;
}
});
$("#tempsave").on('click', function() {
if (checklogin() && checktitle() && checkcontent() && checkcode()) {
sweetAlert({
title : "您的文章已保存 !",
text : "Your blog has been saved.",
type : "success"
}, function() {
document.getElementById("newblog").action=".newBlogServlet?state=0";
document.getElementById("newblog").submit();
});
} else {
return false;
}
});