百度富文本编辑器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%


原文地址:https://www.cnblogs.com/php-qiuwei/p/9525424.html