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)起來(lái)'; } } </script> </head> <body> <button οnclick='showClock()'>點(diǎn)擊顯示時(shí)鐘</button> <div id='clock'> </div> <button οnclick='runClock()'>動(dòng)起來(lái)</button> </body></html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)經(jīng)驗(yàn)分享2. vue項(xiàng)目登錄成功拿到令牌跳轉(zhuǎn)失敗401無(wú)登錄信息的解決3. php使用正則驗(yàn)證密碼字段的復(fù)雜強(qiáng)度原理詳細(xì)講解 原創(chuàng)4. JSP+Servlet實(shí)現(xiàn)文件上傳到服務(wù)器功能5. uniapp自定義驗(yàn)證碼輸入框并隱藏光標(biāo)6. 淺談?dòng)蓀osition屬性引申的css進(jìn)階討論7. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向8. CSS可以做的幾個(gè)令你嘆為觀止的實(shí)例分享9. vue前端RSA加密java后端解密的方法實(shí)現(xiàn)10. asp批量添加修改刪除操作示例代碼

網(wǎng)公網(wǎng)安備