zoukankan      html  css  js  c++  java
  • 百度富文本编辑器Ueditor上传图片时标签中添加宽高

    ueditor.all.js中:直接搜索callback()
     1 function callback(){
     2     try{
     3         var link, json, loader,
     4             body = (iframe.contentDocument || iframe.contentWindow.document).body,
     5             result = body.innerText || body.textContent || '';
     6         json = (new Function("return " + result))();
     7         link = me.options.imageUrlPrefix + json.url;
     8         if(json.state == 'SUCCESS' && json.url) {
     9             loader = me.document.getElementById(loadingId);
    10             loader.setAttribute('src', link);
    11             loader.setAttribute('_src', link);
    12 
    13             /*==================自己添加的代码====================*/
    14             var width='';
    15             var height='';
    16             // 创建对象
    17             var img = new Image();
    18             // 设置图片的src
    19             img.src = link;
    20             //console.log("link:"+link);
    21             img.onload = function(){
    22                 console.log(''+img.width+',height:'+img.height);
    23                 width=img.width;
    24                 height=img.height;
    25                 loader.setAttribute('width',width);
    26                 loader.setAttribute('height',height);
    27             };
    28             /*===================结束========================*/
    29 
    30             loader.setAttribute('title', json.title || '');
    31             loader.setAttribute('alt', json.original || '');
    32             loader.removeAttribute('id');
    33             domUtils.removeClasses(loader, 'loadingclass');
    34         } else {
    35             showErrorLoader && showErrorLoader(json.state);
    36         }
    37     }catch(er){
    38         showErrorLoader && showErrorLoader(me.getLang('simpleupload.loadError'));
    39     }
    40     form.reset();
    41     domUtils.un(iframe, 'load', callback);
    42 }

    或者自己设定大小

     1 /*==================自己添加的代码====================*/
     2 var width='';
     3 var height='';
     4 // 创建对象
     5 var img = new Image();
     6 // 设置图片的src
     7 img.src = link;
     8 //console.log("link:"+link);
     9 img.onload = function(){
    10     console.log(''+img.width+',height:'+img.height);
    11     width=img.width;
    12     height=img.height;
    13     loader.setAttribute('width','340px');
    14     // loader.setAttribute('height',height);
    15 };
    16 /*===================结束========================*/

    或者

    loader.setAttribute('width','100%');

    前端显示也100%


  • 相关阅读:
    win7-64系统下安装nodejs
    Vue项目使用npm run dev出现npm ERR! missing script: dev
    本地环境时覆盖Apollo配置
    金蝶K3序时簿页面增加物料即时库存显示功能
    LeetCode——开篇
    url 与 params 参数的常见操作归纳汇总(含精心准备的注释)
    如何让 arcgis require 里定义的方法可以在全局访问?
    字体图标库 iconfont、iconmoon 的维护管理与使用探索
    【转载】ES5-ES12 常用语法特性
    一次 outline 去除经验(非继承属性,看着像继承)
  • 原文地址:https://www.cnblogs.com/php-qiuwei/p/9525424.html
Copyright © 2011-2022 走看看