·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> 百度ueditor 上传图片后如何设置样式

百度ueditor 上传图片后如何设置样式

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23
百度ueditor 上传图片后如何设置样式

最近项目中遇到一个问题,UEditor上传图片后,在内容展示会修改图片样式。但是表情也是img标签,所以全局修改是有问题的,

所以只能着手修改一下插件的代码。

首先找到图片上传的服务器段文件。这里主要是php讲解

找到php目录下Uploader.class.php 337行

public function getFileInfo()   {       return array(           "state" => $this->stateInfo,           "url" => $this->fullName,           "title" => $this->fileName,           "original" => $this->oriName,           "type" => $this->fileType,   "class"=> "aaa"           "size" => $this->fileSize,       );   }

这样返回的json 多一个class 属性的值

一种是修改js

找到ueditor.all.js 中 24461 如下代码

修改js

function callback(){try{var link, json, loader,body = (iframe.contentDocument || iframe.contentWindow.document).body,result = body.innerText || body.textContent || '';json = (new Function("return " + result))();link = me.options.imageUrlPRefix + json.url;if(json.state == 'SUCCESS' && json.url) {loader = me.document.getElementById(loadingId);loader.setAttribute('src', link);loader.setAttribute('_src', link);loader.setAttribute('class', json.class || ''); //添加行代码loader.setAttribute('title', json.title || '');loader.setAttribute('alt', json.original || '');loader.removeAttribute('id');domUtils.removeClasses(loader, 'loadingclass');} else {showErrorLoader && showErrorLoader(json.state);}}catch(er){showErrorLoader && showErrorLoader(me.getLang('simpleupload.loadError'));}form.reset();domUtils.un(iframe, 'load', callback);}

这样上传下图片你就能看见上传的图片都多了个样式。