<select id="year" style="width: 100px;"></select>
<select id="month" style="width: 100px;"></select>
//初始化年
var now = new Date();
var nowYear = now.getFullYear();
for (var i = nowYear;i <= nowYear+10; i++) {
var option = $("<option/>").val(i).text(i);
$(‘#year‘).append(option);
}
$(‘#year‘).val(nowYear);
//初始化月
for (var i = 1;i <= 12; i++) {
var j=i<10?‘0‘+i:i;
var option = $("<option/>").val(j).text(j);
$(‘#month‘).append(option);
}
var month = now.getMonth() + 1;
month = month < 10 ? ‘0‘ + month : month;
$(‘#month‘).val(month);
时间: 2024-10-15 13:09:58