<script language="JavaScript">
function getMonthDays(year,month)
{
var date1 = new Date(year, month-1, 1);
var returnValue = 0;
while(date1.getMonth()+1 == month)
{
returnValue++;
date1.setTime(date1.getTime()+1000*60*60*24);
}
return returnValue;
}
alert(getMonthDays(2004,2));
alert(getMonthDays(2005,2));
alert(getMonthDays(2005,7));
</script>

解决方案 »

  1.   

    dateObj = new Date(year, month, date[, hours[, minutes[, seconds[,ms]]]]) 参数
    dateObj必选项。要赋值为 Date 对象的变量名。dateVal必选项。如果是数字值,dateVal 表示指定日期与 1970 年 1 月 1 日午夜间全球标准时间 的毫秒数。如果是字符串,则 dateVal 按照 parse 方法中的规则进行解析。dateVal 参数也可以是从某些 ActiveX(R) 对象返回的 VT_DATE 值。year必选项。完整的年份,比如,1976(而不是 76)。month必选项。表示的月份,是从 0 到 11 之间的整数( 1 月至 12 月)。
      

  2.   

    <script language="JavaScript">
    function getMonthDays(year,month){
    return new Date(year, month, 0).getDate();
    }
    alert(getMonthDays(2004,2));
    alert(getMonthDays(2005,2));
    alert(getMonthDays(2005,7));
    </script>