我想知道,使用此功能创建addEventListener
,是否有必要并可能使用removeEventListener
删除?
getFavTable = () => {
document.addEventListener('DOMNodeInserted', () => {
if (document.querySelector('#todayfavtable') != null) {
document.querySelector('#todayfavtable').scrollIntoView();
window.scrollBy(0, -50);
document.querySelector('#todayfavtable').offsetTop });
} else {
window.scrollTo(0, 0);
}
});
}
答案 0 :(得分:0)
没有必要删除它,以防你希望它持续用户在该页面上的整个时间,但是如果你想要禁用它,你必须保存对该回调函数的引用,就像你那样将能够正确使用removeEventListener
。