跳转至

生日快樂

HTML

比如:祝 博 士 生 日 快 樂!

<!DOCTYPE html>
<html lang="zh-Hant">
<head>
  <meta charset="UTF-8">
  <title>生日祝福</title>
</head>
<body>
  <h2 style="color:#f17beb; text-align:center; display:none;" id="birthday-message"><em><strong>祝 博 士 生 日 快 樂 !</strong></em></h2>
  <script>
    window.addEventListener('load', function() {
      const today = new Date();
      const birthdayWeekStart = new Date(today.getFullYear(), 1, 6); // 2月6日
      birthdayWeekStart.setDate(birthdayWeekStart.getDate() - birthdayWeekStart.getDay()); // 計算該周第一天日期

      const birthdayWeekEnd = new Date(birthdayWeekStart);
      birthdayWeekEnd.setDate(birthdayWeekStart.getDate() + 6); // 計算該周最後一天日期

      if (today >= birthdayWeekStart && today <= birthdayWeekEnd) {
        document.getElementById('birthday-message').style.display = 'block';
      }
    });
  </script>
</body>
</html>
<!DOCTYPE html>
<html lang="zh-Hant">
<head>
  <meta charset="UTF-8">
  <title>生日祝福</title>
</head>
<body>
  <h2 style="color:#f17beb; text-align:center; display:none;" id="birthday-message"><em><strong>祝 JOJO 生 日 快 樂 !</strong></em></h2>
  <script>
    window.addEventListener('load', function() {
      const today = new Date();
      const birthdayWeekStart = new Date(today.getFullYear(), 11, 8); // 12月8日
      birthdayWeekStart.setDate(birthdayWeekStart.getDate() - birthdayWeekStart.getDay()); // 計算該周第一天日期

      const birthdayWeekEnd = new Date(birthdayWeekStart);
      birthdayWeekEnd.setDate(birthdayWeekStart.getDate() + 6); // 計算該周最後一天日期

      if (today >= birthdayWeekStart && today <= birthdayWeekEnd) {
        document.getElementById('birthday-message').style.display = 'block';
      }
    });
  </script>
</body>
</html>