日期:2014-05-16  浏览次数:20368 次

改网上一哥们的Js日历IE各种毛病
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<style>
*{margin:0 auto;padding:0;}
body{font:12px arial;text-align:center;background-color:#f1efef;}
body,p,form{margin:0;padding:0}
body,form{position:relative}
code{font:14px arial;text-align:left;}
img{border:0}
a:link {text-decoration: none;}
a:visited {text-decoration: none;}
a:hover {text-decoration: none;}
a:active {text-decoration: none;}
a{color:#999;cursor:pointer;}
a:active{color:#ddd;}
#da{border:1px solid #999; border-right:none; width:700px; margin-left:100px; margin-top:50px; overflow:hidden; border-top:none; border-bottom:none;}
ul,li{ padding:0px; overflow:0px; margin:0px; list-style-type:none;}
.xingqi{ width:700px; overflow:hidden; }
.xingqi li{border-bottom:1px solid #999;float:left;width:98px; overflow:hidden; border-right:1px solid #999; border-top:1px solid #999; text-align:center;}
#da2 .day{width:98px;height:50px;float:left; border-bottom:1px solid #999; border-right:1px solid #999;}
#da2 .dayin{width:100%;height:100%; text-align:center; }
#button-div{display:none;}
.cls{clear:both;}
</style>
<body>
<div id="button-div"><input type="button" id="button" value="点我"></div>
<div id="da">
<div class="xingqi">
    <ul>
    <li>星期日</li>
    <li>星期一</li>
    <li>星期二</li>
    <li>星期三</li>
    <li>星期四</li>
    <li>星期五</li>
    <li>星期六</li>
    </ul>
    </div>
<div class="cls"></div>
<div id="da2"></div>

</div>

<input type="button" id="back" value="上月" style="margin-left:100px;margin-top:20px;">
<input type="button" id="next" value="下月">

</body>

<script language="javascript">
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