1 回答

TA贡献2037条经验 获得超6个赞
发生这种情况是因为 document.querySelector 返回一个 HtmlElement 对象,该对象表示 dom 中的第一个匹配元素。该对象实际上并不是 dom 元素本身。
调用时,Element.remove()您从其所属的树中删除节点,但元素本身仍保留在分配给变量的内存中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);
}
添加回答
举报