删除所有CK Editor实例

时间:2018-06-01 06:48:11

标签: javascript html ckeditor

在线解决方案无效。

我正在开发一个动态生成HTML的应用程序,我需要在它们上面激活CK编辑器,但是当长度超过1时我得到'这个编辑器已被附加'的错误

这似乎是我想要的,但我尝试通过此解决方案在线完成此操作,但这不起作用

for(name in CKEDITOR.instances)
{
    CKEDITOR.instances[name].destroy(true);
}

我怎么能这样做?

2 个答案:

答案 0 :(得分:2)

您应首先检查该元素的实例是否存在,然后执行操作:

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

答案 1 :(得分:1)

浏览CKEDITOR.instances并销毁每一个。

CKEDITOR.instances.forEach(key) {
   if (CKEDITOR.instances.hasOwnProperty(key) {
       CKEDITOR.instances[key].destroy();
   })
}