我通过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/