// 年度
var date = new Date();
var minYear = 1940,maxMonth = date.getFullYear(),
selectYear = document.getElementById('selectYear');
for (var i = minYear; i<=maxMonth; i++){
var opt = document.createElement('option');
opt.value = i;
opt.innerHTML = i;
selectYear.appendChild(opt);
}
// 月份
var minMonth = 1,maxMonth = 12,
selectMonth = document.getElementById('selectMonth');
for (var i = minMonth; i<=maxMonth; i++){
var opt = document.createElement('option');
opt.value = i;
opt.innerHTML = i;
selectMonth.appendChild(opt);
}
// 預設日期
daysInThisMonth();
// 日期
function daysInThisMonth() {
var date_var = new Date(date.getFullYear(), date.getMonth()+1, 0).getDate();
var minDay = 1,maxDay = date_var,
selectDay = document.getElementById('selectDay');
selectDay.options.length = 0;
for (var i = minDay; i<=maxDay; i++){
var opt = document.createElement('option');
opt.value = i;
opt.innerHTML = i;
if(i == 1){
opt.selected = "true";
}
selectDay.appendChild(opt);
}
}
沒有留言:
張貼留言