CKEditor多个ID的一个实例

时间:2014-11-19 11:42:18

标签: javascript jquery ckeditor

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

我的页面中有这个配置:

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

                ],
            width: "210px",
            height: "140px"
        });

但是我必须一次又一次地为不同的ID而去,而我想做这样的事情:

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

                ],
            width: "210px",
            height: "140px"
        });

1 个答案:

答案 0 :(得分: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 );

或者使用jQuery,匹配以" dsi"开始的所有ID:

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