2014-11-15 21 views
0

我使用CKEditor的JQuery。 我有几个textarea这个。 textarea的名称在内容生成时可能会有所不同。ckeditor实例已经存在之后ajax + jquery

通过这种方式,我使用类,而不是ID:

$('.ckedit').ckeditor(); 

AJAX内容重装之后,我有错误conclose: *实例东西已经存在*

我知道,我可以使用销毁方法为Ckeditor:

if (CKEDITOR.instances['textarea_name']) { 
    CKEDITOR.instances['textarea_name'].destroy(); 
} 

但我不能这样做,因为textarea的名称/ ID可能是几个此时此刻。

我该如何解决这个问题?谢谢,我的英语水平:)

回答

0

我试试这个代码和工作对我来说,当我有一个UpdatePanel在它CKEDITOR遗憾:

ASPX:

的Javascript:

$(document).ready(function() { 
    ReplaceWithCkEditor(); 
}); 

function pageLoad() { 
    ReplaceWithCkEditor(); 
} 

function ReplaceWithCkEditor() { 
    $('textarea').ckeditor(); 
} 

UpdatePanel完成工作后,Microsoft Ajax框架将运行pageLoad函数。然后我用CkEditor替换textarea。

0

谢谢大家。 我解决了这个问题。

之前

$('.ckedit').ckeditor(); 

需要插入:

jQuery.each(CKEDITOR.instances, function(){ 
    eval("CKEDITOR.instances."+this.name+".destroy(true)"); 
}); 
+0

伙计们,我有个好消息。在安装最后一个版本的Ckeditor(4版)后,不需要销毁实例。 :) – hcuser

0

您在您的textarea添加类所见即所得,并调用此功能。当你转换新的textarea使用此功能转换的新闻... textarea与这个类。

CKEDITOR.basePath += 'ckeditor/'; 
CKEDITOR.config.contentsCss = '/ckeditor/contents.css' ;  
function addWysiwyg() 
{ 
    var eldata = $(document).find('.wysiwyg'); 

    console.log(eldata); 
    var config = {}; 
    $(eldata).each(function(){ 
     CKEDITOR.replace(this, config); 
     $(this).removeClass('wysiwyg'); 
    }); 
}