I apologize for the confusion. The issue with your code is that you are immediately calling the 'countdown' function instead of passing it as a callback to 'setInterval'.

To fix this issue, you need to update the 'setInterval' calls as follows:

timer = setInterval(function() {
  countdown(70);
}, 1000);

// ...

timer = setInterval(function() {
  countdown(20);
}, 1000);

By wrapping the 'countdown' function in an anonymous function, you can pass it as a callback to 'setInterval' and ensure that it is executed every second.

JavaScript Countdown Timer - setInterval Issue and Solution

原文地址: https://www.cveoy.top/t/topic/qyt1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录