js 實用方法

1、倒計時
const countDown = (second) => { const s = second % 60; const m = Math.floor(second / 60); return ${00${m}.slice(-2)} : ${00${s}.slice(-2)};};let time = 5 * 60;const timer = setInterval(() => { const show = countDown(time--); console.log(show); if(time < 0) { console.log('倒計時結束!'); clearInterval(timer); }}, 1000);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章