js 倒计时写法
倒计时6s后关闭
var times = 6;
var timer = null; countdown() { this.timer = setInterval(() => { this.times--; if (this.times === 0) { clearInterval(this.timer); // do something } }, 1000) };
如下:
倒计时6s后关闭
var times = 6;
var timer = null; countdown() { this.timer = setInterval(() => { this.times--; if (this.times === 0) { clearInterval(this.timer); // do something } }, 1000) };
如下: