最完美的JS万年历(二)
发表于:2007-06-30来源:作者:点击数:
标签:
/////////////////////////////////////////////////////////////////////////////// var cld; function drawCld(SY,SM) { var i,sD,s,size; cld = new calendar(SY,SM); if(SY1949 SY2051) yDisplay = @#建国@# + (((SY-1949)==1)?@#元@#:SY-1949); if(SY194
///////////////////////////////////////////////////////////////////////////////
var cld;
function drawCld(SY,SM) {
var i,sD,s,size;
cld = new calendar(SY,SM);
if(SY>1949 && SY<2051) yDisplay = @#建国@# + (((SY-1949)==1)?@#元@#:SY-1949);
if(SY<1949 && SY>1900) yDisplay = @#公元@# + (SY);
GZ.innerHTML = yDisplay +@#年 农历@# + cyclical(SY-1900+36) + @#年 【@#+Animals[(SY-4)%12]+@#年】@#;
YMBG.innerHTML = " " + SY + "<BR> " + monthName[SM];
for(i=0;i<42;i++) {
sObj=eval(@#SD@#+ i);
lObj=eval(@#LD@#+ i);
sObj.className = @#@#;
sD = i - cld.firstWeek;
if(sD>-1 && sD<cld.length) { //日期内
sObj.innerHTML = sD+1;
if(cld[sD].isToday) sObj.className = @#todyaColor@#; //今日颜色
sObj.style.color = cld[sD].color; //法定假日颜色
if(cld[sD].lDay==1) //显示农历月
lObj.innerHTML = @#<b>@#+(cld[sD].isLeap?@#闰@#:@#@#) + cld[sD].lMonth + @#月@# + (monthDays(cld[sD].lYear,cld[sD].lMonth)==29?@#小@#:@#大@#)+@#</b>@#;
else //显示农历日
lObj.innerHTML = cDay(cld[sD].lDay);
s=cld[sD].lunarFestival;
if(s.length>0) { //农历节日
if(s.length>6) s = s.substr(0, 4)+@#…@#;
s = s.fontcolor(@#red@#);
}
else { //公历节日
s=cld[sD].solarFestival;
if(s.length>0) {
size = (s.charCodeAt(0)>0 && s.charCodeAt(0)<128)?8:4;
if(s.length>size+2) s = s.substr(0, size)+@#…@#;
s = s.fontcolor(@#blue@#);
}
else { //廿四节气
s=cld[sD].solarTerms;
if(s.length>0) s = s.fontcolor(@#limegreen@#);
}
}
if(s.length>0) lObj.innerHTML = s;
}
else { //非日期
sObj.innerHTML = @#@#;
lObj.innerHTML = @#@#;
}
}
}
function changeCld() {
var y,m;
y=CLD.SY.selectedIndex+1900;
m=CLD.SM.selectedIndex;
drawCld(y,m);
}
function pushBtm(K) {
switch (K){
case @#YU@# :
if(CLD.SY.selectedIndex>0) CLD.SY.selectedIndex--;
break;
case @#YD@# :
if(CLD.SY.selectedIndex<150) CLD.SY.selectedIndex++;
break;
case @#MU@# :
if(CLD.SM.selectedIndex>0) {
CLD.SM.selectedIndex--;
}
else {
CLD.SM.selectedIndex=11;
if(CLD.SY.selectedIndex>0) CLD.SY.selectedIndex--;
}
break;
case @#MD@# :
if(CLD.SM.selectedIndex<11) {
CLD.SM.selectedIndex++;
}
else {
CLD.SM.selectedIndex=0;
if(CLD.SY.selectedIndex<150) CLD.SY.selectedIndex++;
}
break;
default :
CLD.SY.selectedIndex=tY-1900;
CLD.SM.selectedIndex=tM;
}
changeCld();
}
var Today = new Date();
var tY = Today.getFullYear();
var tM = Today.getMonth();
var tD = Today.getDate();
//////////////////////////////////////////////////////////////////////////////
var width = "130";
var offsetx = 2;
var offsety = 8;
var x = 0;
var y = 0;
var snow = 0;
var sw = 0;
var cnt = 0;
var dStyle;
document.onmousemove = mEvn;
//显示详细日期资料
function mOvr(v) {
var s,festival;
var sObj=eval(@#SD@#+ v);
var d=sObj.innerHTML-1;
//sYear,sMonth,sDay,week,
//lYear,lMonth,lDay,isLeap,
//cYear,cMonth,cDay
if(sObj.innerHTML!=@#@#) {
sObj.style.cursor = @#s-resize@#;
if(cld[d].solarTerms == @#@# && cld[d].solarFestival == @#@# && cld[d].lunarFestival == @#@#)
festival = @#@#;
else
festival = @#<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR="#
CCFFCC"><TR><
TD>@#+
@#<FONT COLOR="#000000" STYLE="font-size:9pt;">@#+cld[d].solarTerms + @# @# + cld[d].solarFestival + @# @# + cld[d].lunarFestival+@#</FONT></TD>@#+
@#</TR></TABLE>@#;
s= @#<TABLE WIDTH="130" BORDER=0 CELLPADDING="2" CELLSPACING=0 BGCOLOR="#000066" style="filter:Alpha(opacity=80)"><TR><TD>@# +
@#<TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD ALIGN="right"><FONT COLOR="#ffffff" STYLE="font-size:9pt;">@#+
cld[d].sYear+@# 年 @#+cld[d].sMonth+@# 月 @#+cld[d].sDay+@# 日<br>星期@#+cld[d].week+@#<br>@#+
@#<font color="violet">农历@#+(cld[d].isLeap?@#闰 @#:@# @#)+cld[d].lMonth+@# 月 @#+cld[d].lDay+@# 日</font><br>@#+
@#<font color="yellow">@#+cld[d].cYear+@#年 @#+cld[d].cMonth+@#月 @#+cld[d].cDay + @#日</font>@#+
@#</FONT></TD></TR></TABLE>@#+ festival +@#</TD></TR></TABLE>@#;
document.all["detail"].innerHTML = s;
if (snow == 0) {
dStyle.left = x+offsetx-(width/2);
dStyle.top = y+offsety;
dStyle.visibility = "visible";
snow = 1;
}
}
}
//清除详细日期资料
function mOut() {
if ( cnt >= 1 ) { sw = 0; }
if ( sw == 0 ) { snow = 0; dStyle.visibility = "hidden";}
else cnt++;
}
//取得位置
function mEvn() {
x=event.x;
y=event.y;
if (document.body.scrollLeft)
{x=event.x+document.body.scrollLeft; y=event.y+document.body.scrollTop;}
if (snow){
dStyle.left = x+offsetx-(width/2);
dStyle.top = y+offsety;
}
}
///////////////////////////////////////////////////////////////////////////
function initialize() {
dStyle = detail.style;
CLD.SY.selectedIndex=tY-1900;
CLD.SM.selectedIndex=tM;
drawCld(tY,tM);
CLD.TZ.selectedIndex=getCookie("TZ");
changeTZ();
tick();
}
function terminate(){
setCookie("TZ",CLD.TZ.selectedIndex);
}
function setCookie(name, value) {
var today = new Date();
var expires = new Date();
expires.setTime(today.getTime() + 1000*60*60*24*365);
document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString();
}
function getCookie(Name) {
var search = Name + "=";
if(document.cookie.length > 0) {
offset = document.cookie.indexOf(search);
if(offset != -1) {
offset += search.length;
end = document.cookie.indexOf(";", offset);
if(end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(offset, end));
}
else return "";
}
}
原文转自:http://www.ltesting.net