【问题标题】:Add a <div> inside CKEditor without embedding a <div> button on toolbar在 CKEditor 中添加 <div> 而不在工具栏上嵌入 <div> 按钮
【发布时间】:2015-07-06 22:06:03
【问题描述】:

我想配置 CKEditor,就像它应该在输入区域内有一个 div。如下图所示,但我想从工具栏中删除div button(我在图像中标记)。

我的代码在这里:

<form>
       <textarea id="contents" name="contents">
            &lt;div id=&quot;mydiv&quot; style=&quot;border:1px solid red;margin: 0 auto;width:780px;height:1200px;margin-top:-18px;&quot;&gt; my div &lt;/div&gt;
        </textarea>

         <script src="//cdn.ckeditor.com/4.5.1/full/ckeditor.js"></script>
        <script>

     var Editor   =   CKEDITOR.replace( 'contents', {uiColor: '#88aa22'});
            Editor.config.toolbar = [
                {name: 'first', items: ['Bold', 'Italic', 'Underline', 'Find', 'Replace']},
                {name: 'second', items: ['SelectAll', 'Cut', 'Copy', 'Paste', '-', 'Undo', 'Redo']},
                {name: 'therd', items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock']},
                {name: 'forth', items: ['Smiley', 'SpecialChar', 'NumberedList', 'BulletedList']},
                {name: 'fifth', items: ['Blockquote','HorizontalRule','Maximize', 'Preview']},
                '/',
                {name: 'last', items: ['Font', 'FontSize', 'Styles', 'Format','CreateDiv']}
            ];
             Editor.config.forcePasteAsPlainText = true;
             function Send(){
             var data = CKEDITOR.instances.contents.getData();
             alert(data);
         }
        </script>

</form>

我为你创建的小提琴在这里:https://jsfiddle.net/t4jmo09g/

我想要的结果:

我正在尝试在编辑器中创建一个类似页面的环境。

我该怎么办?

【问题讨论】:

    标签: javascript jquery html ckeditor editor


    【解决方案1】:

    您可以从config.toolbar 中排除'CreateDiv',然后定义config.extraAllowedContent = 'div[dir,id,lang,title](*){*}' 以允许任何类、任何样式但具有有限属性集的div,这是Div 插件的默认配置。

    extraAllowedContent 是必要的,因为 CKEditor 4.1.x 的功能对应于可编辑的内容。因此,如果您从工具栏中删除该功能,您也会告诉编辑器清除相关类型的内容 (html)。很简单——没有 Div 插件,内容中没有 &lt;div&gt;。

    但如果我是你,我可能会用 config.removePlugins = 'div' 完全摆脱插件,然后只用 config.extraAllowedContent 玩,因为加载你不使用的插件是没有意义的。

    阅读更多关于 config.extraAllowedContent、config.removePlugins 和 common problems 的内容过滤。还有一个official guide 关于CKEditor 中的高级内容过滤器。

    【讨论】:

    • 这个过期时间是什么意思div[dir,id,lang,title](*){*}请告诉我。
    • @G4uKu3_Gaurav 请参阅this 指南。
    【解决方案2】:

    您是否正在尝试做一些使用共享空间可以轻松完成的事情?

    http://sdk.ckeditor.com/samples/sharedspace.html

    您可以在中间放置较长的工具栏和底部栏以及较窄的主体,可选地被其他 div 包围。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-09
      • 2016-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-13
      • 2014-09-01
      相关资源
      最近更新 更多