Rumah > Soal Jawab > teks badan
P粉5236250802023-08-02 11:47:11
<!DOCTYPE html> <html> <head> <title>Birthday Countdown</title> </head> <body> <form onsubmit="calculateDaysLeft(event)"> <label for="bday">Enter your birthday:</label> <input type="date" id="bday" name="bday" required> <input type="submit" value="Submit"> </form> <script> function calculateDaysLeft(event) { event.preventDefault(); // Prevent form submission to avoid page reload // Get the user's birthday from the input field let userBirthday = new Date(document.getElementById("bday").value); // Get the current date let currentDate = new Date(); // Calculate the difference in milliseconds let difference = userBirthday.getTime() - currentDate.getTime(); // Calculate the difference in days and show the alert let totalDays = Math.ceil(difference / (1000 * 3600 * 24)); window.alert(`There are ${totalDays} days left until your birthday!`); } </script> </body> </html>