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
- ๋ณ์
- Spring
- Ajax
- like
- order by
- ์๋ฐ์คํฌ๋ฆฝํธ
- JS
- ์ปจํธ๋กค๋ฌ
- JSP
- ํจ์
- ๋ช ๋ น์ด
- ๋ฐฑํฑ
- ํ๋ก๊ทธ๋๋จธ์ค
- DATE_FORMAT
- ํ ์ด๋ธ
- optionํ๊ทธ
- ๋์ปค
- oracle
- post๋ฐฉ์
- ๋์ ํ ์ด๋ธ
- ๋ฐฐ์ด
- ์ธ๋ผ์ธ๋ทฐ
- ์ฝํ
- ๋ฆฌ๋ ์ค
- SQL
- select
- Update
- MySQL
- ๋์
- JavaScript
Archives
- Today
- Total
bom's happy life
[JS๋์ ์บ๋ฆฐ๋] ํ ,์ผ ๊ธฐ๋ณธ๊ฐ disabled, ์ค๋๋ ์ง ํฌํจํ ์ด์ ๋ ์ง disabled ๋ณธ๋ฌธ
Deveolpment Study๐๏ธ/Javascript
[JS๋์ ์บ๋ฆฐ๋] ํ ,์ผ ๊ธฐ๋ณธ๊ฐ disabled, ์ค๋๋ ์ง ํฌํจํ ์ด์ ๋ ์ง disabled
bompeach 2024. 5. 13. 16:34<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; // ์ ํ๋ ์
์ ๋ฐฐ๊ฒฝ์
}
label {
margin-right: 20px;
}
input[type="radio"] {
margin-right: 5px;
}
.disabled {
color: #d3d3d3;
background-color: #f9f9f9;
pointer-events: none; /* ํด๋ฆญ ๋นํ์ฑํ */
}
var today = new Date();
var currentYear = today.getFullYear();
var currentMonth = today.getMonth() + 1;
window.onload = function() {
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 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;
for (let i = 0; i < 6; i++) {
const row = calendarBody.insertRow();
let rowHasDates = false;
for (let j = 0; j < 7; j++) {
const cell = row.insertCell();
const currentDate = new Date(year, month - 1, date);
const dayOfWeek = currentDate.getDay(); // ์ผ์์ผ์ 0, ํ ์์ผ์ 6
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 (currentDate < today || dayOfWeek === 0 || dayOfWeek === 6) {
cell.classList.add('disabled');
cell.style.color = '#d3d3d3'; // ๋นํ์ฑํ๋ ๋ ์ง ์์
} else {
(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);
}
if (today.getFullYear() === year && today.getMonth() + 1 === month && today.getDate() === date) {
cell.style.border = "3px solid #586e9a"; // ์ค๋๋ ์ง ํ
๋๋ฆฌ ์คํ์ผ
}
date++;
rowHasDates = true;
}
}
if (!rowHasDates) {
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}๋
${monthNames[month - 1]} ${date}์ผ`;
displayArea.textContent = formattedDate;
// ์๊ฐ๋ ๋ผ๋์ค ๋ฒํผ ์์ฑ
const times = ["09:30", "10:00", "10:30", "14:00", "14:30", "15:00", "15:30", "16:00", "16:30", "17:00"];
const timeSelector = document.createElement('div');
times.forEach(time => {
const label = document.createElement('label');
const radioInput = document.createElement('input');
radioInput.type = 'radio';
radioInput.name = 'appointmentTime';
radioInput.value = time;
label.appendChild(radioInput);
label.appendChild(document.createTextNode(time));
timeSelector.appendChild(label);
radioInput.addEventListener('click', function() {
console.log(`์๊ฐ์ ํ : ${time} `);
});
});
displayArea.appendChild(timeSelector);
}
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);
}
'Deveolpment Study๐๏ธ > Javascript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] ์บ๋ฆฐ๋ ์์ ํ ์คํธ ์์ฑํ๊ธฐ (0) | 2024.06.13 |
---|---|
[JS] ๋์ ์บ๋ฆฐ๋ ์์ค์ฝ๋ (0) | 2024.05.13 |
[JS] ๋ค์ํ ์ฐจํธ(๊ทธ๋ํ) (0) | 2024.04.23 |
[JS] toISOString() ์ฌ์ฉํ์ฌ ์์๋ ์ง ์ ํ ์ ๋ง์นจ๋ ์ง 2์ฃผ๋ค๋ก ์๋๊ณ์ฐ๋๊ฒ ํ๊ธฐ (1) | 2024.02.05 |
[JS] ์ต์ ์ ํ ์ input ํ์ฑ ๋นํ์ฑ ์ ์ด (0) | 2024.02.01 |