百度ueditor组件上传图片后如何设置图片里的alt属性
来源:绵阳动力网络公司  时间:2016-01-18  阅读:39

网站建设的后台管理系统中经常用到百度ueditor组件,使用上传图片后,自动将上传图片显示在编辑器中,也就是插入了一个<img>标签。并设置了一个alt属性,其值是上传图片时的本地路径。暂时没发现哪里可以配置这个值。在查看发布的内容时,看到alt的值是一个磁盘路径,有点别扭。

可以在编辑完内容,保存到数据库时过滤下,修改alt的内容,也可以直接修改源码:

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('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); 
} 
 
  • 电话咨询

  • 0816-2318288