在jquery中添加多个CKEditor实例

时间:2011-07-14 16:28:46

标签: jquery ckeditor

我正在尝试各种WYSIWYG javascript文本区域。如果我尝试使用jquery在我的屏幕上的每个<textarea>上放置一个CKEditor,编辑器都显示正常,但它们不会保存。我试过了:

$(function() {
$('.editors').ckeditor();
});

$(function() {
$('.editors').each(function(index, element){
    $(element).ckeditor();
});
});

在这两种情况下,每个文本区域都有一个CKEditor,但它不会保存。如果我手动添加所有编辑器

$(function() {
CKEDITOR.replace('contactText');
CKEDITOR.replace('edit_footer_text');
CKEDITOR.replace('termsText');
});

$(function() {
$('#contactText').ckeditor();
$('#edit_footer_text').ckeditor();
$('#termsText').ckeditor();
});

这三个字段都有编辑器,然后保存。

我正在尝试将一些代码放在此项目的标准模板中,这样如果我们想要文本区域的编辑器,他们只需要将类“编辑器”添加到它们中,这就是我寻找的原因jQuery解决方案。这确实适用于tinymce:

$(function() {
     $('.editors').tinymce({
           script_url : '/common/tiny_mce/tiny_mce.js',
               // General options
               mode : "textareas",
              theme : "advanced",
         })
});

1 个答案:

答案 0 :(得分:13)

实际上,jQuery Adapter for CKEditor默认不更新表单元素,你需要用当前的id替换编辑器。

$(function() {
$('.editors').each(function(){
    CKEDITOR.replace( $(this).attr('id') );
});
});

Reference