CKeditor的实例已经存在

Mar*_*rkP 8 jquery ckeditor

我已经在Stack溢出上发现了一些类似的帖子,但没有一个有效的答案.

我在页面上有几个标签,根据他们点击的标签,他们会看到一个特定的标签.在其中一个标签中有一个CKeditor,它是在点击li时启动的.当用户将该特定选项卡单击到另一个选项卡上,然后返回时会出现以下错误:

未捕获编辑器实例"employDesc"已附加到提供的元素.

这是JS:

    $('.addVacancy').click( function() {
        if(CKEDITOR.instances.employDesc)  {
            alert('instance exists');
            var editor = CKEDITOR.instances[employDesc];
            if (editor) { 
                editor.destroy(true); 
            } 
            alert('distroyed');
        }   
        CKEDITOR.replace('employDesc');
    });
Run Code Online (Sandbox Code Playgroud)

两个警报都会出现,但随着控制台中出现错误而中断.有人能帮忙吗?

谢谢

Alf*_*oML 15

您正在尝试使用名为的变量employDesc,您应该使用CKEDITOR.instances["employDesc"]; 要不就

$('.addVacancy').click( function() {
    var editor = CKEDITOR.instances.employDesc;
    if (editor) {
        alert('instance exists');
        editor.destroy(true); 
        alert('destroyed');
    }   
    CKEDITOR.replace('employDesc');
});
Run Code Online (Sandbox Code Playgroud)

这和你试图做的一样.