第二次ajax加载后CKEditor消失

Fla*_*Cat 2 ajax jquery ckeditor

我通过ajax获取此代码:

<script>
$(function(){
$('#responseContent').ckeditor();
});
</script>
<textarea id='responseContent'></textarea>
Run Code Online (Sandbox Code Playgroud)

它成功生成了一个CKEditor窗格,用于精美的文本编辑.

当第二次调用同一段代码时,我得到一个空白区域.奇怪的是,当我对textarea/ckeditor应该在哪里做"检查元素"时,它说:

<textarea id="responseContent" style="visibility: hidden; "></textarea>
Run Code Online (Sandbox Code Playgroud)

所以,作为我的专业黑客,我jQuery它所以是可见性:可见.CSS陷入困境,但结果看起来并没有什么不同.

你如何让ckeditor工作...一直......用ajax生成的数据?

编辑:为了清楚,我不相信这是一个CSS问题.我相信这是一个jquery/ckeditor问题.

Fla*_*Cat 6

在这里找到答案:CKEditor实例已经存在

if(CKEDITOR.instances[editorName]) {
delete CKEDITOR.instances[editorName];
CKEDITOR.replace(editorName);
}
Run Code Online (Sandbox Code Playgroud)

我不确定的一件事(作为ckeditor noob)是"editorName".这是在其上创建的元素的ID.我相信它也可以是类名,如果你用它来创建它.

所以,在我原来问题的例子中:

<script>
    $(function(){
    $('#responseContent').ckeditor();
});
</script>
<textarea id='responseContent'></textarea>
Run Code Online (Sandbox Code Playgroud)

我会像这样解决它:

if(CKEDITOR.instances["responseContent"]) {
    delete CKEDITOR.instances["responseContent"];
    // I replaced this step
    // CKEDITOR.replace("responseContent");
    // With this:
    $('#responseContent').ckeditor();
}
Run Code Online (Sandbox Code Playgroud)