1 回答

TA貢獻(xiàn)2037條經(jīng)驗(yàn) 獲得超6個(gè)贊
發(fā)生這種情況是因?yàn)?document.querySelector 返回一個(gè) HtmlElement 對(duì)象,該對(duì)象表示 dom 中的第一個(gè)匹配元素。該對(duì)象實(shí)際上并不是 dom 元素本身。
調(diào)用時(shí),Element.remove()您從其所屬的樹(shù)中刪除節(jié)點(diǎn),但元素本身仍保留在分配給變量的內(nèi)存中LoadMoreButton。如果您希望變量LoadMoreButton從 dom 中刪除后為 null,則可以為其賦值 null。
var LoadMoreButton = document.querySelector('.loadMore');
setInterval(function () {
LoadMoreButton.remove();
LoadMoreButton = null;
}, 10000);
var timer = null;
timer = window.setInterval(function () {
if (LoadMoreButton !== null) {
LoadMoreProducts();
} else if (LoadMoreButton === null) {
StopLoadingProducts();
}
}, 1000);
function LoadMoreProducts() {}
function StopLoadingProducts() {
clearInterval(timer);
}
添加回答
舉報(bào)