jquery - 第二次 ajax 加载后 CKEditor 消失

标签 jquery ajax ckeditor

我通过ajax获取此代码:

<script>
$(function(){
$('#responseContent').ckeditor();
});
</script>
<textarea id='responseContent'></textarea>

它成功生成了一个 CKEditor Pane ,用于漂亮的文本编辑。

当第二次调用同一段代码时,我得到一个空白区域。奇怪的是,当我对 textarea/ckeditor 应该在的位置执行“检查元素”时,它说:

<textarea id="responseContent" style="visibility: hidden; "></textarea>

所以,作为一名专业黑客,我将 jQuery 做到了可见性:可见。 CSS 卡住了,但结果看起来没有任何不同。

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

编辑: 需要明确的是,我不认为这是 CSS 问题。我相信这是一个 jquery/ckeditor 问题。

最佳答案

在这里找到答案:CKEditor instance already exists

if(CKEDITOR.instances[editorName]) {
delete CKEDITOR.instances[editorName];
CKEDITOR.replace(editorName);
}

我不确定的一件事(作为一个 ckeditor 菜鸟)是“editorName”。这是创建它的元素的 ID。我相信它也可能是类名,如果您使用它来创建它的话。

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

<script>
    $(function(){
    $('#responseContent').ckeditor();
});
</script>
<textarea id='responseContent'></textarea>

我会这样修复它:

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

关于jquery - 第二次 ajax 加载后 CKEditor 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5735317/

相关文章:

jquery - 在滚动条上显示 div

javascript - AJAX 调用 C# Web 方法以返回列表

javascript - 替换ckeditor中的内容标签html

tags - CKEditor防止<p>开头

jquery - Visual Studio html/css 更改问题

javascript - 如何计算总和?

Jquery ajax 和成功事件?

javascript - 创建一个简单的 CKEditor 插件 - 选择下拉列表

javascript - jQuery:在父元素中查找冒泡事件的触发元素

javascript - If-Modified-Since header 使 CORS OPTIONS 请求失败