超出最大调用堆栈大小,试图在我的div中补足计数值

nbysray5  于 2021-09-13  发布在  Java
关注(0)|答案(1)|浏览(246)

正在尝试将我的div中的innertext从0更改为div中的值。您能告诉我-为什么调用堆栈大小超过了,我试图创建条件以保留我的递归-但它不起作用吗

const itemsToCount = document.querySelectorAll('.customers'); 

function counter (item) {
    let stopPoint = Number(item.innerText.slice(0,-1));
    let counterNum = 0; 
    function increase () {  
        if (counterNum === stopPoint) {
            item.innerText = `${item}+`
            return; 
        } else {
            setTimeout(() => {
                item.innerText = counterNum; 

            }, 100)
            counterNum += 1;
            return increase(); 
        }

    }
    increase()
}

Array.from(itemsToCount).forEach(item => {
    counter(item)
})

我的html看起来像

<div class="wrapper">
                      <p class="experience__counter customers">250+</p>
                      <p class="experience__counter customers">20+</p>
                      <p class="experience__counter customers">150+</p>

                    </div>
                  </div>
sgtfey8w

sgtfey8w1#

嘿,根据我的说法,queryselectorall返回一个集合,所以你不能像这样更改它的内部文本。您必须使用这个--itemstocount[0]这里0是索引尝试使用这个

相关问题