我正在尝试从设置侦听器的不同函数中删除具有绑定变量的事件侦听器。
我已经从相同的函数中发送了this post that describes how to remove a bound listener,这与我试图做的事情不同:
function testBind(var1,var2){
//remove the bound event from within this function <<<
alert('bound event now removed');
}
function setEvent(){
var addEvent = document.getElementById("testBtn");
var boundYes = yesFunction.bind( this, this );
addEvent.addEventListener('mouseup', boundYes);
}
我找到的所有示例都在设置事件侦听器的同一函数中删除了事件侦听器:
addEvent.removeEventListener("mouseup", boundYes );
我知道使用bind每次都会创建一个新的事件侦听器,要删除该侦听器,您需要通过相同的变量来设置和删除它。
如何正确地从testBind
函数中删除事件侦听器?
https://stackoverflow.com/questions/56728723
复制相似问题