用JavaScript写一个能开始和暂停的时钟
作者:互联网
//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>
标签:function,fn2,JavaScript,number,60,var,暂停,parseInt,时钟 来源: https://www.cnblogs.com/ykwqbsw/p/16548606.html