87,914
社区成员
发帖
与我相关
我的任务
分享
<script>
function Calendar(startyear,endyear){
this.year = new Array()
var j=0
for(var i = startyear;i<=endyear;i++)
{this.year[j]=i;
j++}
this.month=[1,2,3,4,5,6,7,8,9,10,11,12]
this.day=[[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31],[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28],[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31],[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31],[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31],[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31],[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31],[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]]
}
Calendar.prototype.Createselect=function(){
var sele1 = document.createElement("select")
sele1.id="year"
document.body.appendChild(sele1)
var sele2 = document.createElement("select")
sele2.id="month"
document.body.appendChild(sele2)
var sele3 = document.createElement("select")
sele3.id="day"
document.body.appendChild(sele3)
this.Isyear(this.year[0])
this.Initialization()
this.addmonth()
}
Calendar.prototype.Initialization=function(){
for(var i= 0;i<this.year.length;i++)
{document.getElementById("year").options.add(new Option(this.year[i],i))}
for(var i= 0;i<this.month.length;i++)
{document.getElementById("month").options.add(new Option(this.month[i],i))}
for(var i= 0;i<this.day[1].length;i++)
{document.getElementById("day").options.add(new Option(this.day[1][i],i))}
alert(this.day[1]) // 这里出来的是那个数组的东西。。
}
Calendar.prototype.Isyear = function(year){
if (0==year%4&&((year%100!=0)||(year%400==0)))
{this.day[1]=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29]}
else
{this.day[1]=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28]}
}
Calendar.prototype.addyear = function(year){
var obj = document.getElementsById("year")
obj.attachEvent("onchange",this.changeyear)
}
Calendar.prototype.addmonth = function(year){
var obj = document.getElementById("month")
obj.attachEvent("onchange",this.changemonth)
}
Calendar.prototype.changemonth = function(){
document.getElementById("day").length=0
var nowday = this.day[event.srcElement.value]
alert(this.day[1]) // 这里alert出来的是 null
}
window.onload=function(){
var c = new Calendar(2007,2009)
c.Createselect()
}
</script>