UE.Editor处理内容中含有多余图片问题
<script src="/script/ueditor/ueditor.config.js" type="text/javascript" charset="utf-8"></script>
<script src="/script/ueditor/ueditor.all.min.js" type="text/javascript" charset="utf-8"></script>
<table style="border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td> </td>
</tr>
<tr>
<td style="text-align:center;">
<script id="editor" style="width:870px; height: 350px;" type="text/plain"></script>
</td>
</tr>
</tbody>
</table>
UE.getEditor('editor').addListener( 'contentChange', function() {
var tcontent = "<div>" + UE.getEditor('editor').getContent() + "</div>";
var tcontentJS = $(tcontent);
//去除多余的a链接图片
var alinks = tcontentJS.find("a")
if (alinks.length == 0){
return;
}
var changeAFlag = false;
jQuery.each(alinks, function(i, alink) {
if(alink.innerText.length == 0){
tcontentJS.find("a[name='"+alink.name+"']").remove();
changeAFlag = true;
}
});
if (!changeAFlag){
return;
}
var newContents = tcontentJS.html();
UE.getEditor('editor').setContent(newContents);
});