如何去除 ckeditor 上传图片后在原码中留下的 style="..."之类的代码呢?

发布于 2022-09-01 17:13:01 字数 125 浏览 11 评论 0

做完了编辑器的上传图片功能,发现个问题...

图片上传成功后将图片添加到文本里面后,img图片会多了个style="..."的属性, 这影响了我做手机端的适配
有没有办法去掉的.求助

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

病女 2022-09-08 17:13:01
CKEDITOR.on('instanceReady', function (ev) {
    var editor = ev.editor,
        dataProcessor = editor.dataProcessor,
        htmlFilter = dataProcessor && dataProcessor.htmlFilter;

    // Out self closing tags the HTML4 way, like <br>.
    dataProcessor.writer.selfClosingEnd = '>';

    // Make output formatting behave similar to FCKeditor
    var dtd = CKEDITOR.dtd;
    for (var e in CKEDITOR.tools.extend({}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent)) {
        dataProcessor.writer.setRules(e,
            {
                indent: true,
                breakBeforeOpen: true,
                breakAfterOpen: false,
                breakBeforeClose: !dtd[e]['#'],
                breakAfterClose: true
            });
    }

    // Output properties as attributes, not styles.
    htmlFilter.addRules(
    {
        elements:
        {
            $: function (element) {
                // Output dimensions of images as width and height
                if (element.name == 'img') {
                    var style = element.attributes.style;
                    delete element.attributes.style;
                }

                if (!element.attributes.style)
                    delete element.attributes.style;

                return element;
            }
        },

        attributes:
            {
                style: function (value, element) {
                    // Return #RGB for background and border colors
                    return convertRGBToHex(value);
                }
            }
    });
});
咆哮 2022-09-08 17:13:01

1楼威武也解决了我的问题~谢谢啦

dawn曙光 2022-09-08 17:13:01

想请教一个问题 你会做秒杀软件么

棒棒糖 2022-09-08 17:13:01

楼主找到方法了吗?
今天百度了一天终于找织梦侠找到方法了
http://www.2l3.net/help/modif...
拿走不谢哈!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文