【发布时间】:2015-12-18 13:33:48
【问题描述】:
我创建了一个带有一些文本的页面,点击某个DIV 会出现一个内联编辑器。
我需要销毁新创建的实例,但我不能。我在CKEditor API the destroy() method 中找到了,但它对我不起作用。
这是我的代码:
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
}
错误是:Uncaught TypeError: Cannot read property 'destroy' of undefined
事实上,以下打印产生了这些结果:
console.log("editor: " + editor); //prints "editor: [object Object]"
console.log("CKEDITOR.instances.editor: " + CKEDITOR.instances.editor); //prints "CKEDITOR.instances.editor: undefined"
为什么?如何获取刚刚创建的编辑器实例以便随后销毁?
【问题讨论】:
-
CKEDITOR.instances.editor != 'undefined'- 为什么要引用?实际上是undefined。你不能只使用editor.destroy()吗? -
@raina77ow
editor.destroy()产生同样的错误 -
那你能显示 HTML 吗?有一组有限的元素可以转换为 CKEditor 实例。
-
转念一想,这里确实有问题:从source 来看,
editor可以是 null 或 CKEditor 实例,在任何情况下都不应该是undefined。你能调试CKEDITOR.inline看看发生了什么吗? -
@raina77ow 我添加了 html 帖子。显然编辑器与 DIV 相关联。
标签: javascript ckeditor instance destroy