<!DOCTYPE HTML> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> p { text-align: center; font-size: 60px; margin-top: 0px; } </style> </head> <body> <p id="timer"></p> <script> // Set the date we're counting to var countDownDate = new Date("Nov 19, 2020 13:00:00").getTime(); // Update the countdown every second var updateEverySecond = setInterval(function() { // Get today's date and time var now = new Date().getTime(); // Find the remaining time between now and the count down date var remaining = countDownDate - now; // Time calculations for days, hours, minutes, and seconds var days = Math.floor(remaining / (1000 * 60 * 60 * 24)); var hours = Math.floor((remaining % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var mins = Math.floor((remaining % 1000 * 60 * 60)) / (1000 * 60)); var sec = Math.floor((remaining % (1000 * 60)) / 1000); // Output the result in an element with id="timer" document.getElementById("timer").innerHTML = days + "d " + hours + "h " + mins + "m " + sec + "s "; // If the countdown is over, display a message if (remaining < 0) { clearInterval(updateEverySecond); document.getElementById("timer").innerHTML = "EXPIRED"; } }, 1000); </script> </body> </html>以上是我的index.html文件的内容。这是我关注的 w3schools 页面的链接: https://www.w3schools.com/howto/howto_js_countdown.asp 我尝试在项目目录中创建一个 server.js 文件,我可以包含该内容文件,或任何其他文件,如果这可以澄清我的问题。任何帮助表示赞赏!
添加回答
举报
0/150
提交
取消