Cats萌萌
我觉得这样可能更简单一些,绑定事件时返回一个用来解绑的函数,需要解绑时就直接调用它,就可以了。function addEvent(element,type,fn,data,_this){ _this = _this ? _this : element; var bound = bindFunction(_this,fn,data); if(element.addEventListener){ element.addEventListener(type,bound,false); }else if(element.attachEvent){ element.attachEvent('on'+type,bound); }else{ element['on'+type] = fn.apply(_this,[arguments,data]); } return function(){ if(element.removeEventListener){ element.removeEventListener(type,bound,false); }else if(element.attachEvent){ element.detachEvent('on'+type,bound); }else{ element['on'+type] = null; } };}//绑定var unbinder = addEvent(/*此处省略*/);//解除上面的绑定unbinder();