1 回答

TA貢獻2037條經(jīng)驗 獲得超6個贊
發(fā)生這種情況是因為 document.querySelector 返回一個 HtmlElement 對象,該對象表示 dom 中的第一個匹配元素。該對象實際上并不是 dom 元素本身。
調(diào)用時,Element.remove()您從其所屬的樹中刪除節(jié)點,但元素本身仍保留在分配給變量的內(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);
}
添加回答
舉報