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>&nbsp;</td>
            </tr>
            <tr>
                <td style="text-align:center;">
                      <script id="editor" style="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);
    });

原文地址:https://www.cnblogs.com/xiaoQ0725/p/8274712.html