Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Update
- ํ๋ก๊ทธ๋๋จธ์ค
- ๋ณ์
- SQL
- ์ฝํ
- Spring
- ํจ์
- DATE_FORMAT
- ์๋ฐ์คํฌ๋ฆฝํธ
- Ajax
- JSP
- post๋ฐฉ์
- ํ ์ด๋ธ
- ๋ฐฑํฑ
- ๋ช ๋ น์ด
- ๋์
- ๋์ ํ ์ด๋ธ
- order by
- optionํ๊ทธ
- ๋์ปค
- ๋ฐฐ์ด
- ์ธ๋ผ์ธ๋ทฐ
- like
- MySQL
- oracle
- select
- ๋ฆฌ๋ ์ค
- JS
- JavaScript
- ์ปจํธ๋กค๋ฌ
Archives
- Today
- Total
bom's happy life
[JS] ๋์ ์บ๋ฆฐ๋ ์์ค์ฝ๋ ๋ณธ๋ฌธ
<div id="calendar-controls">
<button id="prevMonth">โ</button>
<span id="currentYearMonth"></span>
<button id="nextMonth">โท</button>
</div>
<div id="calendar"></div>
<div id="time-slots" style="display:none;">
</div>
<div id="selectedDateTime"></div>
table {
width: 400px;
height: 343px;
border-collapse: collapse;
text-align: center;
}
th, td {
border: 1px solid #ccc;
padding: 8px;
text-align: center;
}
th.day-name { /* ์์ผ ํ์ ๋ถ๋ถ์ ์คํ์ผ */
background-color: transparent; /* ๋ฐฐ๊ฒฝ ํฌ๋ช
*/
border: none; /* ํ
๋๋ฆฌ ์ ๊ฑฐ */
color: #4a506b; /* ๊ธ์์ ํ์ */
}
td.date-cell { /* ๋ ์ง ์
์คํ์ผ */
cursor: pointer; /* ์ปค์๋ฅผ ํฌ์ธํฐ๋ก ์ค์ */
}
td.date-cell:hover {
background-color:#586e9a;
color:white;
}
button {
padding: 10px;
margin: 5px;
background-color: #f9f9f9;
border: none;
cursor: pointer;
}
#calendar-controls {
width: 400px;
text-align: center;
margin-bottom: 20px;
}
.selected {
background-color: #e63c64; // ์ ํ๋ ์
์ ๋ฐฐ๊ฒฝ์
color: white !; // ์ ํ๋ ์
์ ํ
์คํธ ์์
}
window.onload = function() {
const today = new Date();
currentYear = today.getFullYear();
currentMonth = today.getMonth() + 1;
createCalendar(currentYear, currentMonth);
document.getElementById('prevMonth').addEventListener('click', function() {
changeMonth(-1);
});
document.getElementById('nextMonth').addEventListener('click', function() {
changeMonth(1);
});
};
function createCalendar(year, month) {
const container = document.getElementById('calendar');
container.innerHTML = '';
const daysInMonth = new Date(year, month, 0).getDate();
const firstDayOfMonth = new Date(year, month - 1, 1).getDay();
const today = new Date(); // ์ค๋ ๋ ์ง ๊ฐ์ฒด๋ฅผ ์์ฑ
const table = document.createElement('table');
const header = table.createTHead();
const headerRow = header.insertRow(0);
const dayNames = ['์ผ', '์', 'ํ', '์', '๋ชฉ', '๊ธ', 'ํ '];
dayNames.forEach(day => {
const cell = document.createElement('th');
cell.textContent = day;
headerRow.appendChild(cell);
});
const calendarBody = table.createTBody();
let date = 1;
let usedRows = 0;
for (let i = 0; i < 6; i++) { // ์ต๋ 6์ฃผ
const row = calendarBody.insertRow();
let rowHasDates = false;
for (let j = 0; j < 7; j++) {
const cell = row.insertCell();
if (i === 0 && j < firstDayOfMonth) {
cell.classList.add('empty');
} else if (date > daysInMonth) {
cell.classList.add('empty');
} else {
cell.textContent = date;
cell.classList.add('date-cell');
if (today.getFullYear() === year && today.getMonth() + 1 === month && today.getDate() === date) {
cell.style.border = "3px solid #586e9a"; // ์ค๋ ๋ ์ง์ ํ
๋๋ฆฌ ์ถ๊ฐ
}
(function(currentYear, currentMonth, currentDate) {
cell.addEventListener('click', function() {
document.querySelectorAll('.date-cell').forEach(c => c.classList.remove('selected'));
this.classList.add('selected');
displaySelectedDate(currentYear, currentMonth, currentDate);
});
})(year, month, date);
date++;
rowHasDates = true;
}
}
if (rowHasDates) {
usedRows++; // ์ค์ ๋ ์ง๊ฐ ์๋ ํ๋ง ์ฆ๊ฐ
} else {
calendarBody.removeChild(row); // ๋ถํ์ํ ํ ์ ๊ฑฐ
}
}
container.appendChild(table);
updateHeader(year, month);
}
function displaySelectedDate(year, month, date) {
const displayArea = document.getElementById('selectedDateTime');
const monthNames = ["1์", "2์", "3์", "4์", "5์", "6์", "7์", "8์", "9์", "10์", "11์", "12์"];
const formattedDate = `${year}๋
${month}์ ${date}์ผ`;
displayArea.textContent = formattedDate;
}
function updateHeader(year, month) {
const monthNames = ["1์", "2์", "3์", "4์", "5์", "6์", "7์", "8์", "9์", "10์", "11์", "12์"];
document.getElementById('currentYearMonth').textContent = `${year}๋
${monthNames[month - 1]}`;
}
function changeMonth(delta) {
currentMonth += delta;
if (currentMonth < 1) {
currentYear -= 1;
currentMonth = 12;
} else if (currentMonth > 12) {
currentYear += 1;
currentMonth = 1;
}
createCalendar(currentYear, currentMonth);
}