项目中用到的富文本框编辑器wangEditor

文档地址: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()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值