1、JS部分代碼
複製代碼代碼如下:
/**
* 提交表單
*/
function submitForm(action, actName, objName, formName,blogType){
$("#"+formName).attr("action",action);
//var f = document.getElementsByTagName("form")[0];
//alert(f.action);
$("#"+formName).form({
onSubmit:function(){
checkInput();//檢查輸入項是否為空
} ,
success:function(data){
if (data == "success"){
$.messager.alert('提示','<br>日誌發表成功!','info');
}else{
$.messager.alert('提示','<br>日誌發表失敗!','warning');
}
}
});
}
/**
* 發表日誌
*/
function publishBlog() {
submitForm("http://localhost:8090/webplus3/_web/sns/createBlog.do?_p=YXM9Mw__","發表","日誌","fm1","publish");
}
2、html部分
複製代碼代碼如下:
<form style="padding: 10px 8px;" method="post" action="" id="fm1" name="fm1">
<div style="margin-bottom: 10px;">
<span style="padding-right: 10px;">標題:</span>
<input type="text" id="title" name="blog.title" maxlength="30">
</div>
<div style="margin-bottom: 10px;">
<span style="padding-right: 10px;">內容:</span>
<input type="text" id="content" name="blog.content" maxlength="3000">
</div>
<button type="submit" id="saveBlogButton" onclick="publishBlog()">
<span>發表</span>
</button>
</form>