js實(shí)現(xiàn)時(shí)鐘定時(shí)器
本文實(shí)例為大家分享了js實(shí)現(xiàn)時(shí)鐘定時(shí)器的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html><html> <head> <meta charset='UTF-8'> <title>時(shí)鐘</title> <script type='text/javascript'> function showClock(){ // 1. 獲取當(dāng)前時(shí)間 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ì)時(shí)操作 id = setInterval('showClock()',1000); flag = false; btn.innerHTML = '停止'; }else{ // 停止計(jì)時(shí)操作 clearInterval(id); flag = true; btn.innerHTML = '動(dòng)起來'; } } </script> </head> <body> <button οnclick='showClock()'>點(diǎn)擊顯示時(shí)鐘</button> <div id='clock'> </div> <button οnclick='runClock()'>動(dòng)起來</button> </body></html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP的Global.asa文件技巧用法2. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)3. ASP中if語(yǔ)句、select 、while循環(huán)的使用方法4. ASP中常用的22個(gè)FSO文件操作函數(shù)整理5. SharePoint Server 2019新特性介紹6. 告別AJAX實(shí)現(xiàn)無刷新提交表單7. Vue+elementUI下拉框自定義顏色選擇器方式8. PHP函數(shù)原理理解詳談9. XML入門的常見問題(四)10. 使用css實(shí)現(xiàn)全兼容tooltip提示框
