我实现了这个功能来根据选择的月份添加天来选择列表,但它不起作用。
function daysInMonth() {
var year = document.getElementById(year).value;
var month = document.getElementById(month).value;
var dayscount = new Date(year,month, 0).getDate();
var select = document.getElementById(day);
for (var c = 1 ; c <= dayscount ; c++){
var option = document.createElement("option");
option.text = c ;
select.appendChild(option);
}
}
这是html:
<select name="evmonth" id = "month" onchange="daysInMonth()">