CKEDITOR自定义配置问题

时间:2015-10-26 11:37:58

标签: javascript html5 ckeditor ckeditor4.x

我想自定义ckeditor。但它不起作用,即始终显示默认视图。 我的HTML是

<div>
    <textarea name="editor1" id="" cols="30" rows="10" class="editor"></textarea>
</div>

和js代码是

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
    <script src="https://cdn.ckeditor.com/4.5.4/standard/ckeditor.js"></script>
    <script>
        CKEDITOR.editorConfig = function( config ) {
            config.toolbarGroups = [
                { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
                { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
                { name: 'links', groups: [ 'links' ] },
                { name: 'insert', groups: [ 'insert' ] },
                { name: 'forms', groups: [ 'forms' ] },
                { name: 'tools', groups: [ 'tools' ] },
                { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
                { name: 'others', groups: [ 'others' ] },
                { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
                { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
                { name: 'styles', groups: [ 'styles' ] },
                { name: 'colors', groups: [ 'colors' ] },
                { name: 'about', groups: [ 'about' ] }
            ];

            config.removeButtons = 'Subscript,Superscript,Source,Image,Table,HorizontalRule,SpecialChar,Anchor,Paste,PasteText,PasteFromWord,Styles,About,Format,RemoveFormat';
        };
        CKEDITOR.replace('editor1');

我的问题在哪里?谢谢。

1 个答案:

答案 0 :(得分:0)

请改为使用。

CKEDITOR.replace( 'editor1', {
  toolbarGroups: [
    { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
    { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
    { name: 'links', groups: [ 'links' ] },
    { name: 'insert', groups: [ 'insert' ] },
    { name: 'forms', groups: [ 'forms' ] },
    { name: 'tools', groups: [ 'tools' ] },
    { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
    { name: 'others', groups: [ 'others' ] },
    { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
    { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
    { name: 'styles', groups: [ 'styles' ] },
    { name: 'colors', groups: [ 'colors' ] },
    { name: 'about', groups: [ 'about' ] }
  ],
  removeButtons: 'Subscript,Superscript,Source,Image,Table,HorizontalRule,SpecialChar,Anchor,Paste,PasteText,PasteFromWord,Styles,About,Format,RemoveFormat'
} )

Fiddle