gpt4 book ai didi

javascript - CKEditor 实例已经存在

转载 作者:IT王子 更新时间:2023-10-29 02:42:38 27 4
gpt4 key购买 nike

我正在使用 jquery 对话框来呈现表单(通过 AJAX 获取)。在某些表格上,我为文本区域使用了 CKEditor。编辑器在第一次加载时显示良好。

当用户取消对话框时,我将删除内容,以便在以后的请求中重新加载它们。问题是,一旦重新加载对话框,CKEditor 就会声称编辑器已经存在。

uncaught exception: [CKEDITOR.editor] The instance "textarea_name" already exists.

API 包含一个销毁现有编辑器的方法,我看到有人声称这是一个解决方案:

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

这对我不起作用,因为我收到了一个新错误:

TypeError: Result of expression 'i.contentWindow' [null] is not an object.

这个错误似乎发生在“destroy()”而不是“replace()”。有没有人经历过这种情况并找到了不同的解决方案?

是否可以“重新渲染”现有的编辑器,而不是销毁和替换它?

已更新 Here is another question处理同样的问题,但他提供了一个downloadable test case .

最佳答案

为此,您需要在销毁实例时传递 bool 参数 true:

    var editor = CKEDITOR.instances[name];
if (editor) { editor.destroy(true); }
CKEDITOR.replace(name);

关于javascript - CKEditor 实例已经存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1794219/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com