addEventListener绑定传参函数并解绑
<a class="btn">go</a> <a class="remove">remove</a>
var btn = document.getElementsByClassName('btn')[0], remove = document.getElementsByClassName('remove')[0]; var some = function (msg) { console.log(msg) }; // bind 方法pc端有兼容性问题,请注意 var fn = some.bind(null,'哈哈'); btn.addEventListener('click',fn,false); remove.addEventListener('click',function () { btn.removeEventListener('click',fn,false); },false);
作者:冻豆腐
链接:https://www.zhihu.com/question/50885333/answer/123148092
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。