CKEditor多个ID的一个实例

Gab*_*iel 1 javascript jquery ckeditor

我可以为多个ID的CKeditor使用一种配置吗?

我的页面中有此配置:

var editor = CKEDITOR.replace('dsi3',{  
            toolbar :
                [
                    { name: 'basicstyles', items : [ 'Bold','Italic'] },
                    { name: 'paragraph', items : [ 'BulletedList'] }

                ],
            width: "210px",
            height: "140px"
        });
Run Code Online (Sandbox Code Playgroud)

但是我不得不一次又一次地输入不同的ID,相反,我想做这样的事情:

var editor = CKEDITOR.replace('dsi3, dsi4, dsi5, dsi6',{    
            toolbar :
                [
                    { name: 'basicstyles', items : [ 'Bold','Italic'] },
                    { name: 'paragraph', items : [ 'BulletedList'] }

                ],
            width: "210px",
            height: "140px"
        });
Run Code Online (Sandbox Code Playgroud)

Nab*_*imi 5

您可以为选项使用变量。

var editor_config = {
    toolbar: [
        {name: 'basicstyles', items: ['Bold', 'Italic']},
        {name: 'paragraph', items: ['BulletedList']}
    ],
    width: "210px",
    height: "140px"
};

CKEDITOR.replace('dsi3', editor_config );
CKEDITOR.replace('dsi4', editor_config );
CKEDITOR.replace('dsi5', editor_config );
CKEDITOR.replace('dsi6', editor_config );
Run Code Online (Sandbox Code Playgroud)

或使用jQuery,匹配以“ dsi”开头的所有ID:

$('[id^=dsi]').ckeditor({
    toolbar: [
        {name: 'basicstyles', items: ['Bold', 'Italic'] },
        {name: 'paragraph', items: ['BulletedList'] }
    ],
    width: "210px",
    height: "140px"
});
Run Code Online (Sandbox Code Playgroud)