日期:2014-05-16 浏览次数:20368 次
var weekCalendar = { self:null ,hiddenday : new Date() ,d : null ,x : null ,temp : "" ,selectArray : new Array ,$ : function (id){ return document.getElementById(id); } ,Name : function (n){ return document.getElementsByName(n); } ,TagName: function (t){ return document.getElementByTagName(t); } ,init : function (){ self = this; self.d = new Date(); self.hiddenday = self.d; self.initday(self.d); self.$('back').addEventListener('click',self.backmonth); self.$('next').addEventListener('click',self.nextmonth); self.bindListener(); } ,initday : function (day){ var d1 = new Date(day.getFullYear(),day.getMonth(),1); var d2 = new Date(day.getFullYear(),day.getMonth()+1,0); var firstday = new Date(day.getFullYear(),day.getMonth(),1).getDay(); var year = d2.getFullYear(); //当前年 var month = parseInt(d2.getMonth())+1; //当前月份 month = month<10?'0'+month:month; var countDay = 1; //日期从1计数 var dayofmonth = d2.getDate(); //整月有多少天 self.temp=""; for(i=0;i<firstday;i++) self.temp+="<div name=\"day\" class=\"day\"><div name=\"dayin\" class=\"dayin\"></div></div>"; var arr = new Array(); for(;countDay<=dayofmonth;countDay++)arr.push(year+"-"+month+"-"+(countDay<10?'0'+countDay:countDay)); //将日期载入arr for(a in arr) self.temp+="<div name=\"day\" class=\"day\" id=\""+arr[a]+"\"><div name=\"dayin\" class=\"dayin\">"+arr[a]+"</div></div>"; //拼接显示 self.$("da2").innerHTML = self.temp; //将数据放入div中 self.temp=null; } ,nextmonth : function (){ //下个月 self.hiddenday = new Date(self.hiddenday.getFullYear(),self.hiddenday.getMonth()+1,1); self.initday(self