Javascript 如何从CKEditor解除事件绑定?

Javascript 如何从CKEditor解除事件绑定?,javascript,ckeditor,Javascript,Ckeditor,要将某个内容绑定到onChange事件,可以编写类似的内容: CKEDITOR.on( 'currentInstance', function( ev ) { if (CKEDITOR.instances[element_id].checkDirty()) { unsaved_changes = true; } }); 但是。。。如何解开该函数的绑定 上面的代码是我在创建编辑器时使用的一些实例化代码的一部分。当我使用ajax更改页面时,会出现一个

要将某个内容绑定到onChange事件,可以编写类似的内容:

CKEDITOR.on( 'currentInstance', function( ev )
{
       if (CKEDITOR.instances[element_id].checkDirty()) {
          unsaved_changes = true;
       }
});
但是。。。如何解开该函数的绑定

上面的代码是我在创建编辑器时使用的一些实例化代码的一部分。当我使用ajax更改页面时,会出现一个问题,而CKEditor(以及所有其他javascript变量)仍在页面上定义。因此,onChange事件最终会得到多个绑定。。。这可能会导致性能问题。

CKEditor的文档缺少使用Firebug可以找到的“removeListener”方法。我现在添加了它,但可能需要一天时间才能发布

您只需在事件对象上调用该方法,例如:

CKEDITOR.on( 'currentInstance', function( ev )
{
       ev.removeListener();

       if (CKEDITOR.instances[element_id].checkDirty()) {
          unsaved_changes = true;
       }
});
var focus\u action=函数(){
console.log('focus');
}; /*回调必须有自己的名称*/

ckeditor.on('instancerady',函数(){
var\u this=this;

   this.document.on('keyup',function (){
    console.log(ckeditor.checkDirty());
   });

   this.document.on('focus',focus_action); //bind our callback


   this.document.on('blur',function (){
     console.log('blur');
     _this.document.removeListener('focus',focus_action); //remove our callback
     //_this.document.removeAllListeners(); //remove all listeners
   });
})

   this.document.on('keyup',function (){
    console.log(ckeditor.checkDirty());
   });

   this.document.on('focus',focus_action); //bind our callback


   this.document.on('blur',function (){
     console.log('blur');
     _this.document.removeListener('focus',focus_action); //remove our callback
     //_this.document.removeAllListeners(); //remove all listeners
   });