Ckeditor getData的所有实例,其id以“content_”开头

时间:2017-06-15 09:13:10

标签: javascript regex ckeditor push

我想在我的页面中的所有CKEditor实例的getData(),它们的id以“desccription_”开头,将这些数据放入数组但是它不起作用,这是我的代码:

var tab_desc = new Array();
$('#bloc_etapes fieldset').each(function(index)
{       
    var desc_dyn = CKEDITOR.instances[id^="description_"].getData();
    //var desc_dyn = $('#desc_etape'+(index+1)).val();  -------------------------ok with textarea only(without replacing them by CKE)
    tab_desc.push(desc_dyn);
});

如果有人有解决方案,我会感激他!

1 个答案:

答案 0 :(得分:0)

var tab_desc = [];
for (var i in CKEDITOR.instances) {
    if (i.indexOf('description_') == 0) {
        tab_desc.push(CKEDITOR.instances[i].getData());
    }
}

UPDATE: To use textareas without id/name, instantiate them using themselves as DOM elements like this:

$('textarea').each(function() {
    CKEDITOR.replace(this);
});

Then, each instance will be named editor1, editor2 and so on.

UPDATE2: To get data from CKEditor instances whose original textareas have a class named 'my_custom_class', use this:

for (var i in CKEDITOR.instances) {
    if (CKEDITOR.instances[i].element.$.classList.contains('my_custom_class')) {
        console.log(CKEDITOR.instances[i].getData());
    }
}