jquery,ajax和CKEditor - 如何“取消绑定”CKEditor实例

时间:2021-02-20 19:43:38

Hey, I'm using jquery, ajax and CKEditor:

嘿,我正在使用jquery,ajax和CKEditor:

$( '.ckeditor' ).ckeditor();

The first time the page is loaded through ajax the ckeditor() is fired off without a hitch. The second time it fails. Normally when binding you do something like:

第一次通过ajax加载页面时,ckeditor()会毫无障碍地触发。第二次失败。通常在绑定时,您可以执行以下操作:

.unbind('click').bind('click',function{...})

What do I do to unbind ckeditor()?

如何取消绑定ckeditor()?

4 个解决方案

#1


5  

Best I've found is ...

我发现最好的是......

if (CKEDITOR.instances['ckeditor']) {
    CKEDITOR.remove(CKEDITOR.instances['ckeditor']);
}

#2


3  

You can get a CKEDITOR object reference by using:

您可以使用以下命令获取CKEDITOR对象引用:

var editor = $('.ckeditor').ckeditorGet();

and then you can destory it like this:

然后你可以这样破坏它:

CKEDITOR.remove(editor);

#3


2  

I did it long way :). You may count the amount of CK instances this way:

我做得很久:)。您可以通过这种方式计算CK实例的数量:

function countProps(obj) {
    var l = 0;
    for (p in obj) l++;
    return l;
}
if ( countProps(CKEDITOR.instances) ) { 
// to assure you have at least one instance of ckeditor
// you may want to use more complicated checks - in my case I have only one editor 
// instance per page
    editor = $('youreditor').ckeditorGet();
    CKEDITOR.remove(editor); 
}

#4


0  

Simple way Get instances by name , If exist then remove:

简单方法按名称获取实例,如果存在则删除:

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

OR

  var editor = CKEDITOR.instances['name'];
  if (editor) {
      CKEDITOR.remove(editor);
  }

#1


5  

Best I've found is ...

我发现最好的是......

if (CKEDITOR.instances['ckeditor']) {
    CKEDITOR.remove(CKEDITOR.instances['ckeditor']);
}

#2


3  

You can get a CKEDITOR object reference by using:

您可以使用以下命令获取CKEDITOR对象引用:

var editor = $('.ckeditor').ckeditorGet();

and then you can destory it like this:

然后你可以这样破坏它:

CKEDITOR.remove(editor);

#3


2  

I did it long way :). You may count the amount of CK instances this way:

我做得很久:)。您可以通过这种方式计算CK实例的数量:

function countProps(obj) {
    var l = 0;
    for (p in obj) l++;
    return l;
}
if ( countProps(CKEDITOR.instances) ) { 
// to assure you have at least one instance of ckeditor
// you may want to use more complicated checks - in my case I have only one editor 
// instance per page
    editor = $('youreditor').ckeditorGet();
    CKEDITOR.remove(editor); 
}

#4


0  

Simple way Get instances by name , If exist then remove:

简单方法按名称获取实例,如果存在则删除:

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

OR

  var editor = CKEDITOR.instances['name'];
  if (editor) {
      CKEDITOR.remove(editor);
  }