ปฏิทินใน JavaScript

ในส่วนนี้เราจะสร้างปฏิทิน เพื่อความง่าย เราจะทำให้ปฏิทิน แสดงเฉพาะเดือนปัจจุบัน แต่มีแนวคิด ว่าในอนาคตสามารถพัฒนาต่อได้ เพื่อให้สามารถเปลี่ยนเดือนและปีได้ นี่คือ ตัวอย่างสิ่งที่เราควรได้:

นี่คือโครงสร้าง HTML และ CSS ที่คุณสามารถใช้ ในการแก้ไขปัญหา:

html<div id="parent">
  <div id="calendar">
    <table>
      <thead>
        <tr>
          <th>จ.</th>
          <th>อ.</th>
          <th>พ.</th>
          <th>พฤ.</th>
          <th>ศ.</th>
          <th>ส.</th>
          <th>อา.</th>
        </tr>
      </thead>
      <tbody class="body"></tbody>
    </table>
  </div>
</div>
css#parent {
  text-align: center;
}
#calendar {
  display: inline-block;
}
#calendar td, #calendar th {
  padding: 5px 12px;
  border: 1px solid black;
  text-align: center;
}

เริ่มต้น ลองรับลิงก์ไปยังแท็กทั้งหมดที่ต้องการ ลงในตัวแปร และบันทึกเดือนและปีปัจจุบัน:

javascriptlet calendar = document.querySelector('#calendar');
let body = calendar.querySelector('.body');

let date  = new Date();
let year  = date.getFullYear();
let month = date.getMonth();
Задание 1

คัดลอกโครงร่างโค้ดที่ฉันนำเสนอนี้ ไปไว้ที่ตัวคุณเอง