前言
实现35格 5行7列的日历,有效期为30天
实现
var dateObj = {
'date' : new Date(),
//判断闰年
'is_leap' : function()
{
return (this.date.getFullYear() % 100 == 0 ? res = (this.date.getFullYear() % 400 == 0 ? 1 : 0) : res = (this.date.getFullYear() % 4 == 0 ? 1 : 0));
},
//本月第一天星期几
'firstday' : function()
{
return new Date(this.date.getFullYear(), this.date.getMonth(), 1).getDay();
},
//本月天数
'getDayNum' : function()
{
//获取年份
var year = this.date.getFullYear();
//获取当前月份
var mouth = this.date.getMonth() + 1;
//定义当月的天数;
var days ;
//当月份为二月时,根据闰年还是非闰年判断天数
if(mouth == 2)
{
days= year % 4 == 0 ? 29 : 28;
}
else if(mouth == 1 || mouth == 3 || mouth == 5 || mouth == 7 || mouth == 8 || mouth == 10 || mouth == 12){
//月份为:1,3,5,7,8,10,12 时,为大月.则天数为31;
days= 31;
}
else
{
//其他月份,天数为:30.
days= 30;
}
//输出天数
return days;
},
//最后一天星期几
'lastday' : function(num)
{
var getMonth = this.monthNum()
return new Date(this.date.getFullYear(), this.date.getMonth(), getMonth[num]).getDay();
},
//今天日期
'getDates' : function()
{
return this.date.getDate();
},
//今天星期几
'getWeek' : function()
{
return this.date.getDay();
},
//今天星期几
'nowDayWeek' : function()
{
return new Date(this.date.getFullYear(), this.date.getMonth(), this.date.getDates).getDay();
},
//各月总天数
'monthNum' : function()
{
return new Array(31, 28+this.is_leap(this.date.getFullYear()), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
},
//计算所需行数
'getTrNum' : function()
{
monthNum = this.monthNum();
return Math.ceil((monthNum[this.date.getMonth()] + this.firstday()) / 7);
},
//上一个月
'prevMonth ' : function()
{
if (this.tmp_month <= 0)
{
this.tmp_month = 11;
this.tmp_year -=1;
}
else
{
this.tmp_month -= 1;
}
this.calendarShow();
this.yearMonthShow();
return false
},
//下一个月
'nextMonth' : function()
{
if (this.tmp_month >= 11)
{
this.tmp_month = 0;
this.tmp_year += 1;
}
else
{
this.tmp_month += 1;
}
this.calendarShow();
this.yearMonthShow();
re