倒计时
Posted penggedeboke1999
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了倒计时相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> h1{ text-align: left; color: chartreuse; } </style> </head> <body> <h1 id="h1"><span id="ab1"></span></h1 > <h2 id="h1"><span id="ab2"></span></h2> <h3 id="h1"> 新年剩余:<span id="ab3"></span></h3> <script> function fn() { bb1 = document.getElementById(‘ab1‘) bb2 = document.getElementById(‘ab2‘) bb3 = document.getElementById(‘ab3‘) let a1 = new Date() let a2 = a1.getFullYear();//年 let a3 = a1.getMonth()+1;//月 let aa1 = a1.getDay();//星期 let a4 = a1.getDate();//日 let a5 = a1.getHours();//时 let a6 = a1.getMinutes();//分 let a7 = a1.getSeconds();//秒 let a8 = a1.getMilliseconds();//毫秒 var b1 = new Date(2020, 1-1, 23, 23, 59, 59); var time = (b1 - a1) / 1000; var c2 = Math.floor(time / (24 * 60 * 60)) var c3 = Math.floor(time % (24 * 60 * 60) / (60 * 60)) var c4 = Math.floor(time % (24 * 60 * 60) % (60 * 60) / 60); var c5 = Math.floor(time % (24 * 60 * 60) % (60 * 60) % 60); bb1.innerHTML = a2 + ‘年‘+ a3 + ‘月‘ + a4 + ‘日‘ + ‘-‘ + ‘星期‘ + aa1 bb2.innerHTML = a5 + ‘时‘ + a6 + ‘分‘ + ‘:‘ + a7 + ‘秒‘ + a8 + ‘毫秒‘ bb3.innerHTML = c2 + ‘日‘ + c3 + ‘时‘+ c4 + ‘分‘ + c5 + ‘秒‘ } var timer=setInterval(fn, 1000) </script> </body> </html>
以上是关于倒计时的主要内容,如果未能解决你的问题,请参考以下文章