zoukankan      html  css  js  c++  java
  • wangEditor——图片上传失败提示

    wangEditor 官网自定义上传事件:https://www.kancloud.cn/wangfupeng/wangeditor2/123689

    声明:我用的wangEditor版本是2.1.23

    js:

    var editor = new wangEditor('div1');
    // 普通的自定义菜单
    editor.config.menus = [
              ···
    ]; // 上传图片 editor.config.uploadImgUrl = '***'; editor.config.uploadImgFileName = '***'; // 自定义load事件 editor.config.uploadImgFns.onload = function (resultText, xhr) { //不知道是不是因为后台没有返回error,我的图片上传只进入onload方法,我用的谷歌浏览器 // resultText 服务器端返回的text // xhr 是 xmlHttpRequest 对象,IE8、9中不支持 // 上传图片时,已经将图片的名字存在 editor.uploadImgOriginalName var originalName = editor1.uploadImgOriginalName || '';  if(resultText == '0'){ //这个判断取决于后端返回怎样的数据,针对个人情况修改 alert('图片上传失败'); } // 如果 resultText 是图片的url地址,可以这样插入图片: editor.command(null, 'insertHtml', '<img src="' + resultText + '" alt="' + originalName + '" style="max-100%;"/>'); //editor插入HTML
     //如果是vue懒加载的话需要加上data-src属性,否则会加载失败   
    //editor.command(null, 'insertHtml', '<img data-src="'+ resultText + '" src="' + resultText + '" alt="' + originalName + '" style="max-100%;"/>'); //editor插入HTML

    }; editor.create();
  • 相关阅读:
    OS快速开发必备
    YYmodel 郭耀源 底层分析
    UITableView使用总结和性能优化
    文件操作
    DOM解析
    SAX解析
    Gallery
    菜单(menu)
    计时器(Chronometer)、标签(TabHost)
    ListActivity
  • 原文地址:https://www.cnblogs.com/linjiangxian/p/11950559.html
Copyright © 2011-2022 走看看