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基礎(chǔ)知識(shí)VBScript基本元素講解2. Python requests庫(kù)參數(shù)提交的注意事項(xiàng)總結(jié)3. IntelliJ IDEA導(dǎo)入jar包的方法4. ajax請(qǐng)求添加自定義header參數(shù)代碼5. Kotlin + Flow 實(shí)現(xiàn)Android 應(yīng)用初始化任務(wù)啟動(dòng)庫(kù)6. 使用Python和百度語(yǔ)音識(shí)別生成視頻字幕的實(shí)現(xiàn)7. 詳談ajax返回?cái)?shù)據(jù)成功 卻進(jìn)入error的方法8. python操作mysql、excel、pdf的示例9. vue-electron中修改表格內(nèi)容并修改樣式10. Gitlab CI-CD自動(dòng)化部署SpringBoot項(xiàng)目的方法步驟
