富文字編輯器使用開源專案:wangEditor
具體使用請參考下方官網,以下僅做示例,上傳介面請改為實際後端介面
目前上傳介面返回資料是寫死在json裡面的
wangEditor
歡迎使用 wangEditor 富文字編輯器
var E = window.wangEditor; var editor = new E('#editor'); editor.customConfig.uploadImgServer = "../api/upload.json"; editor.customConfig.uploadFileName = 'image'; editor.customConfig.pasteFilterStyle = false; editor.customConfig.uploadImgMaxLength = 5; editor.customConfig.uploadImgHooks = { // 上傳超時 timeout: function (xhr, editor) { layer.msg('上傳超時!') }, // 如果伺服器端返回的不是 {errno:0, data: [...]} 這種格式,可使用該配置 customInsert: function (insertImg, result, editor) { console.log(result); if (result.code == 1) { var url = result.data.url; url.forEach(function (e) { insertImg(e); }) } else { layer.msg(result.msg); } } }; editor.customConfig.customAlert = function (info) { layer.msg(info); }; editor.create();