嘿,我正在使用jquery、ajax和CKEditor:
$( '.ckeditor' ).ckeditor();
第一次通过ajax加载页面时,
ckeditor()
能够顺利启动。但第二次失败了。通常绑定时会做如下操作:.unbind('click').bind('click',function{...})
我要怎么做才能取消绑定ckeditor()
?
if (CKEDITOR.instances['ckeditor']) {
CKEDITOR.remove(CKEDITOR.instances['ckeditor']);
}
您可以通过以下方式获取CKEDITOR对象引用:
var editor = $('.ckeditor').ckeditorGet();
然后你可以像这样销毁它:
CKEDITOR.remove(editor);
我用了较长的方法:). 您可以按照以下方式计算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);
}
简单方法 按名称获取实例,如果存在则删除:
var editor = CKEDITOR.instances['name'];
if (editor) {
editor.destroy(true);
}
或者
var editor = CKEDITOR.instances['name'];
if (editor) {
CKEDITOR.remove(editor);
}