<머리>
js日历效果-wangzf <스타일>
html,body{높이:100%;너비:100%;}
*{margin:0;padding:0;}
.calendarBox{너비:100%;}
#calendar_control{ 배경:#a3a3b4;}
#calendar_control 입력{min-width:inherit;}
#calendarBox{width:100%;height:100%;}
#calendar_str{cursor:pointer;text-align :center;font-weight:lighter;}
#calendar_body td{배경:#f0f0f0;cursor:pointer;}
#calendar_body td.taday{배경:#0CF;}
#calendar_body td.hot {배경:#FF6;}
#calendar_body th{배경:#3f526f;color:#fff;}
#calendar_body td,#calendar_body th{text-align:center;}
<스크립트>
var Calendar={
STR:function(){with(this.data)return "" Y "年," M "月," D "号,星期" WN[W];},
V:함수(spli){with(this)return "" 데이터.Y spli 데이터.M spli 데이터.D},
T:function(){with(this)return 데이터.TABLE},
dnY:function(){with(this){calendarChange(data.Y 1,data.M-1,data.D)}},
dnM:function(){with(this){calendarChange(data.Y ,data.M,data.D)}},
upY:function(){with(this){calendarChange(data.Y-1,data.M-1,data.D)}},
upM:function(){with(this){calendarChange(data.Y,data.M-2,data.D)}},
day:function(o){with(this){data.D=o ;calendarChange(data.Y,data.M-1,data.D)}},
데이터:{Y:null,M:null,D:null,W:null,H:null,U:null, YMD:null,YMD_C:"hot",ARR:null,TABLE:null,MN:null,WN:null,SELECT:null,TADAY:new Date(),TADAY_C:"taday",ROWLEN:7,VALUE:null },
creatTable:function(){with(this){
var table="<테이블 높이=100% 너비=100%>
"
for(var i=0;i" t "";}
for(var i in data.ARR){var showText=data.ARR[i]||" ",br=i�ta.ROWLEN,title,css=" ";
if(!br){table ="
"};
data.ARR[i]?title=data.Y "-" data.M "-" showText:title="";
if(String(data.D)==String(data.ARR[i])){css =" " data.YMD_C;}
if(data.YMD.getFullYear()==data.TADAY .getFullYear()&&data.YMD.getMonth()==data.TADAY.getMonth()&&String(data.TADAY.getDate())==String(data.ARR[i])){css=" " data.TADAY_C }
테이블 ="" showText " | ";
}테이블 ="
"
data.TABLE=테이블;테이블 반환;
}},
calendarStarArr:function(userY,userM,userD){with(this){
var Arr=[];
var now = new Date(userY,userM,userD);
var LastDay = now.getLastDay();
var FirstDayofWeek = now.FirstDayofWeek();
data.YMD=now;data.Y=now.getFullYear();
data.M=now.getMonth() 1;data.D=now.getDate();data.W=now.getDay();
while(Arr.length!=FirstDayofWeek){Arr.push(false)}
for(var i=0;i
while( Arr.length�ta.ROWLEN!=0){Arr.push(false)}
data.ARR=Arr;return Arr;
}},
calendarChange:function(userY,userM,userD){with(this){
calendarStarArr(userY,userM,userD);creatTable()
}},
calendarStar :function(userY,userM,userD){with(this){
data.MN = ["零","一","two","三","四","五","六" ,"七","八","九","十","十一","十이"];
data.WN = ["일","일","이","삼","사","오","六"];
calendarChange(userY,userM,userD);
}},
init:function(){with(this){
Date.prototype.getLastDay=function(){return(new Date(this.getFullYear(),this.getMonth() 1 ,0).getDate())}
Date.prototype.FirstDayofWeek=function(){return(new Date(this.getFullYear(),this.getMonth(),1).getDay())}
CalendarStar(new Date().getFullYear(),new Date().getMonth(),new Date().getDate())
}}
}
|
|
테이블>
<스크립트>
calendar.init()
함수 CalendarChange(){
var Calendar_body=document.getElementById("calendar_body")
calendar_body.innerHTML=calendar.T()//显示表格
var Calendar_str=document.getElementById("calendar_str")
calendar_str.innerHTML=calendar.STR()//显示日期字符串
calendarControl()//调用日历控제
}
calendarChange()/ /日历更新
function CalendarControl(){
var Calendar_str=document.getElementById("calendar_str")
calendar_str.onclick=function(){ Calendar.init();calendarChange()}//返回今天功能实现
var Calendar_dnY=document.getElementById("calendar_dnY")
calendar_dnY.onclick=function(){ Calendar.dnY();calendarChange()}//下一年 功能实现
var Calendar_dnM= document.getElementById("calendar_dnM")
calendar_dnM.onclick=function(){ Calendar.dnM();calendarChange()}//下一月 功能实现
var Calendar_upY=document.getElementById("calendar_upY")
calendar_upY.onclick=function(){ Calendar.upY();calendarChange()}//上一年 功能实现
var Calendar_upM=document.getElementById("calendar_upM")
calendar_upM.onclick=function (){ Calendar.upM();calendarChange()}//上一月 功能实现
var Calendar_day=document.getElementById("calendar_body").getElementsByTagName("td");
for(variable i in Calendar_day){calendar_day[i].onclick=function(){var N=Number(this.innerText);if(N){calendar.day(N);calendarChange()}}} //当天日期 功能实现
}