JS使用setInterval計(jì)時(shí)器實(shí)現(xiàn)挑戰(zhàn)10秒
JS實(shí)現(xiàn)挑戰(zhàn)10秒,主要用到setInterval計(jì)時(shí)器,供大家參考,具體內(nèi)容如下
效果圖
## 完整代碼
<html lang='en'><head><meta charset='UTF-8'><title>js計(jì)時(shí)器</title></head><body><p style='font-size: 2em;color: blue;font-style: italic;'>挑戰(zhàn)10.00秒</p><p style='font-size: 2em;color: red;'>00:00</p><input type='button' value='開始' onclick='oStart()'><input type='button' value='結(jié)束' onclick='oStop()'><input type='button' value='重置' onclick='oReset()'><script> var n= 0, timer=null; var txt=document.getElementById('time'); //開始計(jì)時(shí) function oStart() { clearInterval(timer); timer=setInterval(function () { n++; var m=parseInt(n/60); var s=parseInt(n%60); txt.innerText=toDub(m)+':'+toDub(s); },1000/60); }; //暫停并且清空計(jì)時(shí)器 function oStop() { clearInterval(timer);// txt.innerText='我愛你'; } //重置 function oReset() { txt.innerText='00:00'; n=0; } //補(bǔ)零 function toDub(n){ return n<10?'0'+n:n; }</script></body></html>
更多關(guān)于倒計(jì)時(shí)的文章請(qǐng)查看專題: 《倒計(jì)時(shí)功能》
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. WML語言的基本情況2. python OpenCV學(xué)習(xí)筆記3. Python 多線程之threading 模塊的使用4. react axios 跨域訪問一個(gè)或多個(gè)域名問題5. python 實(shí)現(xiàn)rolling和apply函數(shù)的向下取值操作6. python利用platform模塊獲取系統(tǒng)信息7. CSS代碼檢查工具stylelint的使用方法詳解8. python求numpy中array按列非零元素的平均值案例9. Python過濾掉numpy.array中非nan數(shù)據(jù)實(shí)例10. Python的Tqdm模塊實(shí)現(xiàn)進(jìn)度條配置
