2014-11-15 24 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'); 
    }); 
}