function setMonthSelect(select){ const options = select.options, selectedOption = options[options.selectedIndex], year = selectedOption.value, months = selectedOption.dataset.months, monthStart = months == 9 ? 4 : 1; document.querySelectorAll('[data-control]').forEach(sel =>{ removeOptions(sel); sel.disabled = year ? false : true; }); const monthSelect = document.getElementById('month'); for(let i = 0; i < Number(months); i++) { const month = new Date(year, monthStart+i, 0).getMonth()+1; monthSelect.append(createOption(month,'月')); } } function setDaySelect(month){ const yearSelect = document.getElementById('year'), year = yearSelect.value, countMonths = yearSelect.options[yearSelect.options.selectedIndex].dataset.months; dayStart = (countMonths == 9 && month == 4) ? 2 : 1; if(!year|| !month) return ; const daySelect = document.getElementById('day'), lastDay = (countMonths == 4 && month == 4) ? 1 : new Date(year, month, 0).getDate(); removeOptions(daySelect); for(let i = dayStart; i <= lastDay; i++) daySelect.append(createOption(i,'日')); } function createOption(val,text){ const option = document.createElement('option'); option.textContent = val + text; option.value = val; return option } function removeOptions(parent){ parent.querySelectorAll('option:nth-child(n+2)').forEach(option => option.remove()) }