[英]Is it necessary to `window.removeEventListener('unload')`?
[英]removeEventListener is necessary on document?
我想知道,使用此函數創建一個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);
}
});
}
如果您希望它在用戶一直停留在該頁面上的整個時間都持續存在,則不必刪除它,但是如果要禁用此功能,則必須保存對該回調函數的引用,這樣便可以正確使用removeEventListener
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.