document.removeEventListener javascript

JG7*_*G73 5 javascript events

如何删除这种类型的监听器?

document.addEventListener("onSomething", function(){
  //Do something
});
Run Code Online (Sandbox Code Playgroud)

当尝试删除返回数参数异常时,在第二个参数中使用函数,但我没有函数。

 document.removeEventListener("customUploadComplete")
Run Code Online (Sandbox Code Playgroud)

epa*_*llo 9

您需要引用该函数才能将其删除。因此,将其拉出到一个函数中,以便您可以将其删除。

var thisThing = function(){
  //Do something
}

document.addEventListener("onSomething", thisThing);
document.removeEventListener("onSomething", thisThing);
Run Code Online (Sandbox Code Playgroud)