在作相似新聞網站的web時候,咱們須要對文章進行編輯,這個時候就會用到文本編輯器插件,在衆多文本編輯器插件中比較推薦kindeditor插件。下面具體說說這種插件的用法。php
<link rel="stylesheet" href="<%=path%>/kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="<%=path%>/kindeditor/plugins/code/prettify.css" />
<script charset="utf-8" src="<%=path%>/kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="<%=path%>/kindeditor/lang/zh_CN.js"></script>
<script charset="utf-8" src="<%=path%>/kindeditor/plugins/code/prettify.js"></script>
<tr>
<td align="center">
<textarea name="content" id="content" cols="100" rows="8" style="width:700px;height:400px;visibility:hidden;" ><%=htmlspecialchars(htmlData)%></textarea>
<br />
</td>
</tr>
<script>
var editor1;
KindEditor.ready(function(K) {
editor1 = K.create('textarea[name="content"]', {
cssPath : '<%=path%>/kindeditor/plugins/code/prettify.css',
uploadJson : '<%=path%>/kindeditor/jsp/upload_json.jsp',//標識處理圖片的文件
fileManagerJson : '<%=path%>/kindeditor/jsp/file_manager_json.jsp',
allowFileManager : true,//容許上傳文件和圖片
afterCreate : function() {
this.sync();
},
afterBlur:function(){
this.sync();
}
});
prettyPrint();
});
</script>
//這裏面咱們將圖片保存在attached文件中,須要處理好該文件夾所在的路徑
String savePath = pageContext.getServletContext().getRealPath("/") + "/kindeditor/attached/";
//文件保存目錄URL
String saveUrl = path+"/kindeditor/attached/";
$.ajax(
{
url: "dojkcytj.do?loginID="+window.parent.$("#loginID").val(),
data: {'content':editor1.html(),'type':$("#type").val(),'title':$("#title").val()},
type: "post",
cache : false,
success:function(responseText){
if(responseText == "0"){
alert("添加成功");
window.parent.$("#changePasswdDialog").dialog("close");
$("#btnSave").disabled = true;
$("#btnSave").hide();
return;
}
if(responseText == "1"){
alert("添加失敗");
window.parent.$("#changePasswdDialog").dialog("close");
$("#btnSave").disabled = true;
$("#btnSave").hide();
return;
}
},
error:function(){
alert("system error");
}
}
);
}
<tr>
<td align="center">
<textarea name="content" id="content" cols="100" rows="8" style="width:700px;height:400px;visibility:hidden;" >${HZGS.content}</textarea>
<br />
</td>
</tr>