<!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 文件,我可以包含該內容文件,或任何其他文件,如果這可以澄清我的問題。任何幫助表示贊賞!
w3schools 倒計時器:為什么我的 index.html 文件打開時顯示的是空白頁面而不是
Qyouu
2023-08-18 14:10:21