//sScript
var showTime = document.getElementById('seconds') var id =0 function fn(){ var i = 0 var s = 0 var m = 0 var h = 0 id =setInterval(function(){ i++ s = fn2(i%60) m = fn2(parseInt(i/60%60)) h = fn2(parseInt(i/3600%24)) showTime.innerHTML = `${h}小时 ${m}分钟 ${s}秒` },1000) } function fn2(number){ if(number<10){ return '0'+ number } return number } function fn3(){ clearInterval(id) }
//HTML
<b id="seconds">00:00:00</b> <button id="btn" onclick="fn()">点下试试</button> <button id="btn2" onclick="fn3()">清除</button>
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/278740.html