[英]CKEditor - Destroy an editor instance
我创建了一个带有一些文本的页面,单击某个DIV
出现一个内联编辑器。
我需要销毁新创建的实例,但不能。 我在CKEditor API中找到destroy()
方法,但对我不起作用。 这是我的代码:
HTML
<div id ="0" contenteditable = "true">
<h1Text</h1>
</div>
<div id ="1" contenteditable = "true">
<h2>Other text</h2>
</div>
JS
CKEDITOR.disableAutoInline = false; //turn off automatic editor creation first
var editor = CKEDITOR.inline(idElem); //editor is the editor instance created
if(CKEDITOR.instances.editor != 'undefined' && editor != null) {
CKEDITOR.instances.editor.destroy(); //generates the error
}
错误是: 未捕获的TypeError:无法读取未定义的属性'destroy'
实际上,以下打印产生了这些结果:
console.log("editor: " + editor); //prints "editor: [object Object]"
console.log("CKEDITOR.instances.editor: " + CKEDITOR.instances.editor); //prints "CKEDITOR.instances.editor: undefined"
为什么? 如何获得刚刚创建的编辑器实例,以便随后销毁它?
该( CKEDITOR.instances
)是一个实例数组,您应该对其进行循环以销毁每个实例:
for (key in CKEDITOR.instances) {
CKEDITOR.instances[key].destroy(true);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.