先下载Kingeditor的压缩包文件,解压后放在项目WebContent文件夹下,如图:
然后在需要放置插件的jsp文件中添加js代码,代码如下:
var editor;
KindEditor.ready(function(K) {
editor = K.create('textarea[name="affcontent"]',{
cssPath : '<%=path%>/kindeditor/plugins/code/prettify.css',
uploadJson : '<%=path%>/kindeditor/jsp/upload_json.jsp',
fileManagerJson : '<%=path%>/kindeditor/jsp/file_manager_json.jsp',
allowFileManager : true,
width:"100%",
allowImageUpload:true,
afterBlur:function(){this.sync();}
});
});
在需要放置插件的页面部分HTML代码如下:
<textarea id="affcontent" name="affcontent" style="width:100%;height:120px;" ></textarea>
当需要修改内容,并且要将之前在编辑器上写的数据重新显示在Kingeditor上,可以这样先移除原有的编辑器,然后在重新配置,并设置值。清除编辑器上原有的内容也可以采取这样的方法。
var editor;
KindEditor.remove('#content'); // 先移除之前创建的编辑器
editor = KindEditor.create('#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,
width:"100%",
allowImageUpload:true,
afterBlur: function(){this.sync();}
});
editor.html(data);
Kingeditor下载地址:http://kindeditor.net/down.php