转动功能每 5 秒发生一次,而不是每次单击按钮

turning function to occur every 5 seconds instead of every button click

需要让以下代码每 5 秒运行一次,而不是每次单击按钮(语言:html):

<script>
function goFwd(e) {
  reset();
  if (e.target.classList.contains("next") && currentImage < thumbnails.length-1) {
    currentImage += 1;
    fullSizeImgs[currentImage].classList.add('show');
    caption.textContent = thumbnails[currentImage].firstElementChild.getAttribute('alt');
    hiLiteThumbnail(); 
  } else if (e.target.classList.contains("next") && currentImage === thumbnails.length-1) {
    currentImage = 0;
    fullSizeImgs[currentImage].classList.add('show');
    caption.textContent = thumbnails[currentImage].firstElementChild.getAttribute('alt');
    hiLiteThumbnail();  
  }
}
</script>

您可以使用 javascript 来完成 5 秒的循环。

<script>

window.setInterval(function(){
    goFwd(e)
}, 5000);

</script>

当你想停止循环时,你可以使用:clearInterval()

已更新

您可以让按钮在 5 秒后自动点击。然后你的函数将在每 5 秒后自动调用。

<script>

var btn = document.getElementById('your_button_id');
setInterval(function(){
    btn.click();
}, 5000);  // this will make it click again every 5 seconds

</script>