jsp引入
<!-- 百度编辑器 -->
<script type="text/javascript" src="${ctx}/plugin/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="${ctx}/plugin/ueditor/ueditor.all.min.js"></script>
js代码初始化:
$(function(){
//实例化百度编辑器
loadUE();
});
function loadUE(){
//实例化编辑器
//建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,
//直接调用UE.getEditor('content')就能拿到相关的实例
//var ue = UE.getEditor('content');//仓储服务
UE.getEditor('content', {
toolbars: [
['source', 'undo', 'redo', 'bold', 'italic', 'underline', 'fontborder',
'backcolor', 'fontsize', 'fontfamily', 'justifyleft', 'justifyright',
'justifycenter', 'justifyjustify','date', 'time', 'strikethrough',
'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset',
'blockquote', 'pasteplain', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
'insertimage', 'simpleupload','|',
'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
'forecolor', 'backcolor', 'insertorderedlist',
'insertunorderedlist', 'selectall', 'cleardoc', 'link', 'unlink', 'emotion',
'help','inserttable', 'deletetable']
],
autoHeightEnabled:false,
zIndex:2,
maximumWords:10000,
wordCount:true,
wordCountMsg:"{#count}/10000"
});
//复写UEDITOR的getActionUrl 方法,定义自己的Action
UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
UE.Editor.prototype.getActionUrl = function(action) {
if (action == 'uploadimage' || action == 'uploadfile') {
return SysRootPath+'/mvc/file/upload.do';
} else {
return this._bkGetActionUrl.call(this, action);
}
};
// 复写UEDITOR的getContentLength方法 解决富文本编辑器中一张图片或者一个文件只能算一个字符的问题,可跟数据库字符的长度配合使用
UE.Editor.prototype._bkGetContentLength = UE.Editor.prototype.getContentLength;
UE.Editor.prototype.getContentLength = function(){
return this.getContent().length;
};
}