jquery,ajax和CKEditor - 如何“解除绑定”CKEditor实例

时间:2011-01-13 00:11:02

标签: jquery ajax ckeditor

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

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

首次通过ajax加载页面时,ckeditor()会毫不费力地启动。第二次失败。通常在绑定时,您可以执行以下操作:

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

如何取消绑定ckeditor()

4 个答案:

答案 0 :(得分:5)

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

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

答案 1 :(得分:3)

您可以使用以下方式获取CKEDITOR对象参考:

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

然后你可以这样破坏它:

CKEDITOR.remove(editor);

答案 2 :(得分:2)

我做得很久:)。您可以通过这种方式计算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); 
}

答案 3 :(得分:0)

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

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

OR

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