文档地址:http://www.wangeditor.com/index.html
<div id="div1"></div>
<script src="js/wangEditor.min.js"></script>
var E = window.wangEditor
var editor = new E('#div1')
editor.customConfig.uploadImgShowBase64 = true // 使用 base64 保存图片
// 配置服务器端地址
editor.customConfig.uploadImgServer = url
+ '/fileResultContrller/editorUpLoad'
editor.customConfig.uploadFileName = 'file' //上传的字段
editor.customConfig.uploadImgHooks = {
success : function(xhr, editor, result) {
// 图片上传并返回结果,图片插入成功之后触发
// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象,result 是服务器端返回的结果
if (result.success) {
var s = editor.txt.html(); //获取富文本框的值
s += "<img src='"+result.body.data[0].filePath+result.body.data[0].fileName+"'>";
editor.txt.html(s) //设置富文本框的值
} else {
alert(result.msg)
}
},
fail : function(xhr, editor, result) {
//console.log(result);
// 图片上传并返回结果,但图片插入错误时触发
// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象,result 是服务器端返回的结果
if (result.success) {
var s = editor.txt.html();
s += "<img src='"+result.body.data[0].filePath+result.body.data[0].fileName+"'>";
editor.txt.html(s)
} else {
alert(result.msg)
}
//return false;
//insert(s);
},
error : function(xhr, editor) {
// 图片上传出错时触发
// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象
},
timeout : function(xhr, editor) {
// 图片上传超时时触发
// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象
},
}
// 进行下文提到的其他配置
// ……
// ……
// ……
editor.create()