1 function getCountDays() { 2 var curDate = new Date(); 3 /* 获取当前月份 */ 4 var curMonth = curDate.getMonth(); 5 /* 生成实际的月份: 由于curMonth会比实际月份小1, 故需加1 */ 6 curDate.setMonth(curMonth + 1); 7 /* 将日期设置为0, 这里为什么要这样设置, 我不知道原因, 这是从网上学来的 */
8 curDate.setDate(0); 9 /* 返回当月的天数 */ 10 return curDate.getDate(); 11 } 12 例如, 获取当前月份(现在是3月)的总天数: 13 getCountDays() // 返回31