使用ckeditor编辑内容的时候,默认生成的样式格式都是style=""这样的格式,怎么改变设置,让他不要生成这样的样式

发布于 2021-11-23 10:42:49 字数 257 浏览 381 评论 4

使用ckeditor编辑内容的时候,默认生成的样式格式都是style=""这样的格式,怎么改变设置,让他不要生成这样的样式

现实想让他生成

比如默认是<img src="" style="widht:100px; height:100px;"/>

现在想怎么设置下,能让我在编辑设置这个图片大小的时候,ckeditor自动生成的格式为

<img src="" widht="100" height="100"/>

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

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

发布评论

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

评论(4

甜扑 2021-11-26 20:55:32

确实是这些问题

流心雨 2021-11-26 12:49:35

吃饱撑的。

难得红薯还回答一下。

真要撑的不行了:自己读读生成这些内容的源码,自己改改吧。

成熟的代价 2021-11-25 06:25:57

这个还真没辙的,几个编辑器都是如此

韬韬不绝 2021-11-24 01:20:16

楼主你好,使用CKEditor提供的HTML过滤器接口可解决此类问题,具体方法如下(引用此处):

CKEDITOR.on('instanceReady', function (ev) {
ev.editor.dataProcessor.htmlFilter.addRules(
    {
        elements:
        {
            $: function (element) {
                // Output dimensions of images as width and height
                if (element.name == 'img') {
                    var style = element.attributes.style;

                    if (style) {
                        // Get the width from the style.
                        var match = /(?:^|s)widths*:s*(d+)px/i.exec(style),
                            width = match && match[1];

                        // Get the height from the style.
                        match = /(?:^|s)heights*:s*(d+)px/i.exec(style);
                        var height = match && match[1];

                        if (width) {
                            element.attributes.style = element.attributes.style.replace(/(?:^|s)widths*:s*(d+)px;?/i, '');
                            element.attributes.width = width;
                        }

                        if (height) {
                            element.attributes.style = element.attributes.style.replace(/(?:^|s)heights*:s*(d+)px;?/i, '');
                            element.attributes.height = height;
                        }
                    }
                }



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

                return element;
            }
        }
    });

 

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