js實(shí)現(xiàn)時鐘定時器
本文實(shí)例為大家分享了js實(shí)現(xiàn)時鐘定時器的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html><html> <head> <meta charset='UTF-8'> <title>時鐘</title> <script type='text/javascript'> function showClock(){ // 1. 獲取當(dāng)前時間 var time = new Date(); // document.write(time); var year = time.getFullYear(); // document.write(year); var month = time.getMonth() + 1; // document.write(month); var day = time.getDate(); // var day1 = time.getDay(); // document.write(day1); var hours = time.getHours(); // document.write(hours); var minutes = time.getMinutes(); // document.write(minutes); var seconds = time.getSeconds(); document.getElementById('clock').innerHTML = year+'-'+month+'-'+day+' ' +hours+':'+minutes+':'+seconds; } var flag = true; var id; function runClock(){ var btn = document.getElementById('btn'); if(flag){ // 計(jì)時操作 id = setInterval('showClock()',1000); flag = false; btn.innerHTML = '停止'; }else{ // 停止計(jì)時操作 clearInterval(id); flag = true; btn.innerHTML = '動起來'; } } </script> </head> <body> <button οnclick='showClock()'>點(diǎn)擊顯示時鐘</button> <div id='clock'> </div> <button οnclick='runClock()'>動起來</button> </body></html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向2. 淺談python出錯時traceback的解讀3. python matplotlib:plt.scatter() 大小和顏色參數(shù)詳解4. JSP數(shù)據(jù)交互實(shí)現(xiàn)過程解析5. PHP設(shè)計(jì)模式中工廠模式深入詳解6. Python importlib動態(tài)導(dǎo)入模塊實(shí)現(xiàn)代碼7. Ajax實(shí)現(xiàn)表格中信息不刷新頁面進(jìn)行更新數(shù)據(jù)8. 利用promise及參數(shù)解構(gòu)封裝ajax請求的方法9. windows服務(wù)器使用IIS時thinkphp搜索中文無效問題10. .NET中l(wèi)ambda表達(dá)式合并問題及解決方法
