您的位置:

超牛js版万年历源码,js制作万年历

超牛js版万年历源码,js制作万年历

更新:

本文目录一览:

万年历查询程序. C语言代码

除了天数差计算,基本上是完成了你所提出的功能(天数差计算其实已经提供了年内序数计算方方法,可以在此基础上完善即可)。包含星期计算、公历转农历、农历转公历、节气查询。数据与算法均为原创,绝非网上复制而来。附件中有源代码,同时附带农历数据提取工具,可提取1600到7000年之间的任意年份区间,提取后的数据为压缩数据,占用空间小,同时数据包含数九、三伏、入梅和出梅,非常适合写一份完整的万年历。

部分核心算法函数如下:

//判断闰年,参数:年份,返回值:0-平年,1-闰年

int IsLeapYear(int iYear);

//计算日期在年内的序数,参数:年,月,日,年内序数,返回值:0-失败,1-成功

int GetDaysNumInYear(int iYear, int iMonth, int iDay,int *nDays);

//从年内序数计算月、日,参数:年,年内序数,月,日,返回值:0-失败,1-成功

int GetDateFromDays(int iYear, int nDays, int *iMonth, int *iDay);

//检验年、月、日的合法性,参数:年,月,日,返回值:0-失败,1-成功

int DateCheck(int iYear,int iMonth,int iDay);

//获取农历新年的公历年内序数,参数:农历年,返回值:农历新年的公历年内序数

int LunarGetNewYearOrdinal(int iLunarYear);

//获取农历月的天数,参数:农历年,农历月,是否为闰月,返回值:该农历月的天数,为0代表参数无效

int LunarGetDaysofMonth(int iLunarYear,int iLunarMonth,int IsLeapMonth);

//展开大小月数据表(某一年的),参数:农历年,从上一年十一月开始到当前年份(闰)十二月的每月天数,返回值:0-失败,1-成功

int LunarExpandDX(int iLunarYear,int iDayOfMonth[15]);

//获取农历某一年的闰月情况,参数:农历年,返回值,该年的闰月月份,0表示无闰月

int LunarGetLeapMonth(int iLunarYear);

//公历转农历,参数:公历年、月、日,农历年、月、日,是否为闰月,返回值:0-失败,1-成功

int Gongli2Nongli(int iYear,int iMonth,int iDay,int *iLunarYear,int *iLunarMonth,int *iLunarDay,int *iIsLeapMonth);

//农历转公历,参数:家历年、月、日,是否为闰月,公历年、月、日,返回值:0-失败,1-成功

int Nongli2Gongli(int iLunarYear,int iLunarMonth,int iLunarDay,int iIsLeapMonth,int *iYear,int *iMonth,int *iDay);

//得到指定年份的节气信息,首个是小寒

int GetJieQi(int iYear,int uMonth,unsigned int uJieQi[2]);

//计算星期

unsigned int GetDayOfWeek(int iYear,int uMonth,int uDay);

源代码请看

吧。提取码:ooj7

JS万年历中如何求某天的节气

同样的函数,这个却不能用第402行,按下某日期显示当前节气

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"

HTMLHEADTITLE/TITLE

META http-equiv=Content-Type content=text/html;charset=gb2312

META

META content=All name=robots

META content="Gregorian Solar Calendar and Chinese Lunar Calendar"

name=description

META content=no-cache name=Pragma

META content=no-cache name=Cache-Control

script language="JavaScript" src="jieri.js"/script

script language="JavaScript" src="jieqi.js"/script

SCRIPT language=JScript

var conWeekend = 3;

var lunarInfo=new Array(

0x4bd8,0x4ae0,0xa570,0x54d5,0xd260,0xd950,0x5554,0x56af,0x9ad0,0x55d2,

0x4ae0,0xa5b6,0xa4d0,0xd250,0xd295,0xb54f,0xd6a0,0xada2,0x95b0,0x4977,

0x497f,0xa4b0,0xb4b5,0x6a50,0x6d40,0xab54,0x2b6f,0x9570,0x52f2,0x4970,

0x6566,0xd4a0,0xea50,0x6a95,0x5adf,0x2b60,0x86e3,0x92ef,0xc8d7,0xc95f,

0xd4a0,0xd8a6,0xb55f,0x56a0,0xa5b4,0x25df,0x92d0,0xd2b2,0xa950,0xb557,

0x6ca0,0xb550,0x5355,0x4daf,0xa5b0,0x4573,0x52bf,0xa9a8,0xe950,0x6aa0,

0xaea6,0xab50,0x4b60,0xaae4,0xa570,0x5260,0xf263,0xd950,0x5b57,0x56a0,

0x96d0,0x4dd5,0x4ad0,0xa4d0,0xd4d4,0xd250,0xd558,0xb540,0xb6a0,0x95a6,

0x95bf,0x49b0,0xa974,0xa4b0,0xb27a,0x6a50,0x6d40,0xaf46,0xab60,0x9570,

0x4af5,0x4970,0x64b0,0x74a3,0xea50,0x6b58,0x5ac0,0xab60,0x96d5,0x92e0,

0xc960,0xd954,0xd4a0,0xda50,0x7552,0x56a0,0xabb7,0x25d0,0x92d0,0xcab5,

0xa950,0xb4a0,0xbaa4,0xad50,0x55d9,0x4ba0,0xa5b0,0x5176,0x52bf,0xa930,

0x7954,0x6aa0,0xad50,0x5b52,0x4b60,0xa6e6,0xa4e0,0xd260,0xea65,0xd530,

0x5aa0,0x76a3,0x96d0,0x4afb,0x4ad0,0xa4d0,0xd0b6,0xd25f,0xd520,0xdd45,

0xb5a0,0x56d0,0x55b2,0x49b0,0xa577,0xa4b0,0xaa50,0xb255,0x6d2f,0xada0,

0x4b63,0x937f,0x49f8,0x4970,0x64b0,0x68a6,0xea5f,0x6b20,0xa6c4,0xaaef,

0x92e0,0xd2e3,0xc960,0xd557,0xd4a0,0xda50,0x5d55,0x56a0,0xa6d0,0x55d4,

0x52d0,0xa9b8,0xa950,0xb4a0,0xb6a6,0xad50,0x55a0,0xaba4,0xa5b0,0x52b0,

0xb273,0x6930,0x7337,0x6aa0,0xad50,0x4b55,0x4b6f,0xa570,0x54e4,0xd260,

0xe968,0xd520,0xdaa0,0x6aa6,0x56df,0x4ae0,0xa9d4,0xa4d0,0xd150,0xf252,

0xd520);

var solarMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);

var Gan=new Array("甲","乙","丙","丁","戊","己","庚","辛","壬","癸");

var Zhi=new Array("子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥");

var Animals=new Array("鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪");

var solarTerm = new Array("小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至");

var sTermInfo = new Array(0,21208,42467,63836,85337,107014,128867,150921,173149,195551,218072,240693,263343,285989,308563,331033,353350,375494,397447,419210,440795,462224,483532,504758);

var nStr1 = new Array('日','一','二','三','四','五','六','七','八','九','十');

var nStr2 = new Array('初','十','廿','卅',' ')

var monthName = new Array("1 月","2 月","3 月","4 月","5 月","6 月","7 月","8 月","9 月","10 月","11 月","12 月");

var timeData = {

"Asia 亚洲": { //----------------------------------------------

"Brunei 文莱 ":["+0800","","斯里巴加湾市"],

"Burma 缅甸 ":["+0630","","仰光"],

"Cambodia 柬埔寨 ":["+0700","","金边"],

"China 中国 ":["+0800","","北京、重庆、上海、天津"],

"China(HK,Macau) 中国 ":["+0800","","香港、澳门特区"],

"China(TaiWan) 中国 ":["+0800","","台北、高雄"],

"China(Urumchi) 中国 ":["+0700","","乌鲁木齐"],

"Indonesia 印尼 ":["+0700","","雅加达"],

"Poland 波兰 ":["+0100","","华沙"],

"国际换日线 ":["-1200","","国际换日线"]

}

};

function lYearDays(y) {

var i, sum = 348;

for(i=0x8000; i0x8; i=1) sum += (lunarInfo[y-1900] i)? 1: 0;

return(sum+leapDays(y));

}

function leapDays(y) {

if(leapMonth(y)) return( (lunarInfo[y-1899]0xf)==0xf? 30: 29);

else return(0);

}

function leapMonth(y) {

var lm = lunarInfo[y-1900] 0xf;

return(lm==0xf?0:lm);

}

function monthDays(y,m) {

return( (lunarInfo[y-1900] (0x10000m))? 30: 29 );

}

function Lunar(objDate) {

var i, leap=0, temp=0

var baseDate = new Date(1900,0,31)

var offset = (objDate - baseDate)/86400000

this.dayCyl = offset + 40

this.monCyl = 14

for(i=1900; i2050 offset0; i++) {

temp = lYearDays(i)

offset -= temp

this.monCyl += 12

}

if(offset0) {

offset += temp;

i--;

this.monCyl -= 12

}

this.year = i

this.yearCyl = i-1864

leap = leapMonth(i) //闰哪个月

this.isLeap = false

for(i=1; i13 offset0; i++) {

//闰月

if(leap0 i==(leap+1) this.isLeap==false)

{ --i; this.isLeap = true; temp = leapDays(this.year); }

else

{ temp = monthDays(this.year, i); }

//解除闰月

if(this.isLeap==true i==(leap+1)) this.isLeap = false

offset -= temp

if(this.isLeap == false) this.monCyl ++

}

if(offset==0 leap0 i==leap+1)

if(this.isLeap)

{ this.isLeap = false; }

else

{ this.isLeap = true; --i; --this.monCyl;}

if(offset0){ offset += temp; --i; --this.monCyl; }

this.month = i

this.day = offset + 1

}

function solarDays(y,m) {

if(m==1)

return(((y%4 == 0) (y%100 != 0) || (y%400 == 0))? 29: 28);

else

return(solarMonth[m]);

}

function cyclical(num) {

return(Gan[num%10]+Zhi[num%12]);

}

//============================== 阴历属性

function calElement(sYear,sMonth,sDay,week,lYear,lMonth,lDay,isLeap,cYear,cMonth,cDay) {

this.isToday = false;

//瓣句

this.sYear = sYear; //公元年4位数字

this.sMonth = sMonth; //公元月数字

this.sDay = sDay; //公元日数字

this.week = week; //星期, 1个中文

//农历

this.lYear = lYear; //公元年4位数字

this.lMonth = lMonth; //农历月数字

this.lDay = lDay; //农历日数字

this.isLeap = isLeap; //是否为农历闰月?

//八字

this.cYear = cYear; //年柱, 2个中文

this.cMonth = cMonth; //月柱, 2个中文

this.cDay = cDay; //日柱, 2个中文

this.color = '';

this.lunarFestival = ''; //农历节日

this.solarFestival = ''; //公历节日

this.solarTerms = ''; //节气

}

//===== 某年的第n个节气为几日(从0小寒起算)

function sTerm(y,n) {

var offDate = new Date( ( 31556925974.7*(y-1900) + sTermInfo[n]*60000 ) + Date.UTC(1900,0,6,2,5) );

return(offDate.getUTCDate());

}

function strDate(objDate)

{

var tY = objDate.getFullYear();

var tM = objDate.getMonth()+1;

var tD = objDate.getDate();

var tH = objDate.getHours();

var s;

s=+tY+"年"+tM+"月"+tD+"日"+tH+"时";

return s;

}

function GetTerm(objDate) {

var year=objDate.getFullYear();

var d;

var i;

for (i=1;i23;i+=2) {

d=sTerm(year,i);

if (objDated) break;

}

if (i==1) i=23;

return i;

}

function calendar(y,m) {

var sDObj, lDObj, lY, lM, lD=1, lL, lX=0, tmp1, tmp2, tmp3, BMjqFtvl;

var cY, cM, cD; //年柱,月柱,日柱

var lDPOS = new Array(3);

var n = 0;

var firstLM = 0;

sDObj = new Date(y,m,1,0,0,0,0); //当月一日日期

this.length = solarDays(y,m); //公历当月天数

this.firstWeek = sDObj.getDay(); //公历当月1日星期几

if(m2) cY=cyclical(y-1900+36-1);

else cY=cyclical(y-1900+36);

var term2=sTerm(y,2); //立春日期

var firstNode = sTerm(y,m*2) //返回当月「节」为几日开始

cM = cyclical((y-1900)*12+m+12);

var dayCyclical = Date.UTC(y,m,1,0,0,0,0)/86400000+25567+10;

for(var i=0;ithis.length;i++) {

if(lDlX) {

sDObj = new Date(y,m,i+1); //当月一日日期

lDObj = new Lunar(sDObj); //农历

lY = lDObj.year; //农历年

lM = lDObj.month; //农历月

lD = lDObj.day; //农历日

lL = lDObj.isLeap; //农历是否闰月

lX = lL? leapDays(lY): monthDays(lY,lM); //农历当月最后一天

if(n==0) firstLM = lM;

lDPOS[n++] = i-lD+1;

}

if(m==1 (i+1)==term2) cY=cyclical(y-1900+36);

if((i+1)==firstNode) cM = cyclical((y-1900)*12+m+13);

cD = cyclical(dayCyclical+i);

this[i] = new calElement(y, m+1, i+1, nStr1[(i+this.firstWeek)%7],

lY, lM, lD++, lL,

cY ,cM, cD );

}

sFtv = new Array(

"0101*新年元旦",

"0312 植树节 孙中山逝世纪念日",

"0314 国际警察日")

for(i in sFtv)

if(sFtv[i].match(/^(\d{2})(\d{2})([\s\*])(.+)$/))

if(Number(RegExp.$1)==(m+1)) {

this[Number(RegExp.$2)-1].solarFestival += RegExp.$4 + ' ';

if(RegExp.$3=='*') this[Number(RegExp.$2)-1].color = 'red';

}

}

function cMonth(d){

var s;

switch (d) {

case 1: s = '正'; break;

case 11: s = '冬'; break;

case 12: s = '腊'; break;

break;

default :

s = nStr1[d%12];

}

return(s);

}

function cDay(d){

var s;

switch (d) {

case 10: s = '初十'; break;

case 20: s = '二十'; break;

break;

case 30: s = '三十'; break;

break;

default :

s = nStr2[Math.floor(d/10)];

s += nStr1[d%10];

}

return(s);

}

var cld;

function drawCld(years,months) {

var i,sD,s,size;

cld = new calendar(years,months);

if(years1874 years1909) yDisplay = '光绪' + (((years-1874)==1)?'元':years-1874);

if(years1908 years1912) yDisplay = '宣统' + (((years-1908)==1)?'元':years-1908);

if(years1911 years1950) yDisplay = '民国' + (((years-1911)==1)?'元':years-1911);

if(years1948) yDisplay = '建国font color=red' + (((years-1949)==1)?'元':years-1949);

GZ.innerHTML = yDisplay+'/font年'+'/a '+Animals[(years-4)%12]+'年[农历font color=red' + cyclical(years-1900+36)+'/font年]';

for(i=0;i42;i++) {

sObj=eval('SD'+ i);

lObj=eval('LD'+ i);

sObj.className = '';

sD = i - cld.firstWeek;

if(sD-1 sDcld.length) { //日期内

sObj.innerHTML = sD+1;

if(cld[sD].isToday) sObj.className = 'todyaColor'; //今日颜色

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].solarFestival;

if(s.length0) {//公历节日

size = (s.charCodeAt(0)0 s.charCodeAt(0)128)?8:4;

if(s.lengthsize+2) s = s.substr(0, size)+'...';

s=(s=='黑色星期五')?s.fontcolor('black'):s.fontcolor('blue');

}

else {

s=cld[sD].lunarFestival;

if(s.length0) { //农历节日

if(s.length6) s = s.substr(0, 4)+'...';

s = s.fontcolor('red');

}

else { //廿四节气

s=cld[sD].solarTerms;

if(s.length0) s = s.fontcolor('limegreen');

}

}

if(s.length0) lObj.innerHTML = s;

}

else { //非日期

sObj.innerHTML = '';

lObj.innerHTML = '';

}

}

}

function changeCld() {

var y,m;

y=CLD.years.selectedIndex+1900;

m=CLD.months.selectedIndex;

drawCld(y,m);

}

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,sjqFtvl;

var sObj=eval('SD'+ v);

var d=sObj.innerHTML-1;

if(sObj.innerHTML!='') {

sObj.style.cursor= 'help';

if(cld[d].solarTerms == '' cld[d].solarFestival == '' cld[d].lunarFestival == '')

festival = '';

else

festival = 'TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR="#CCFFCC"TRTD ALIGN="center"'+

'FONT COLOR="#000000" STYLE="font-size:9pt;"'+cld[d].solarTerms + ' ' +'/FONT/TD'+

'/TR/TABLE';

s= 'table border="2" width="140" bordercolor="#0066CC" bgcolor="#FFFBE8" cellpadding="0" cellspacing="0"TRtd' +

'TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0TRTD ALIGN="center"FONT COLOR="#ff00ff" STYLE="font-size:9pt;"'+

cld[d].sYear+'年'+cld[d].sMonth+'月'+cld[d].sDay+'日 星期'+cld[d].week+'br'+

'font color="#FF8000"农历'+cld[d].cYear+'年'+(cld[d].isLeap?' 闰':' ')+cMonth(cld[d].lMonth)+'月'+cDay(cld[d].lDay)+'/fontbr'+

'font color="009900"'+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 jieqi(objDate) {

var year=objDate.getFullYear();

var d; var i; var m

for (i=0;i24;i+=1) {

d=sTerm(year,i);

m=i

if (objDate=d) break;

} return m

}

function mDown(V) {

var sObj=eval('SD'+ V);

var D=sObj.innerHTML-1;

var ya=cld[D].sYear;//获得当前公历日期!

var ma=cld[D].sMonth;

var da=cld[D].sDay;

var Today=new Date(ya,ma,da,0,0,0)

m=jieqi(Today)

document.all.s3.value=m

}

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('');

}

else return('');

}

function initialize() {

dStyle = detail.style;

CLD.years.selectedIndex=tY-1900;

CLD.months.selectedIndex=tM;

drawCld(tY,tM);

}

/SCRIPT

STYLE

.todyaColor {BACKGROUND-COLOR: aqua}

/STYLEMETA content="MSHTML 6.00.2900.2802" name=GENERATOR/HEAD

BODY onload=initialize()

DIV id=detail

style="Z-INDEX: 3; FILTER: shadow(color=#333333,direction=135); WIDTH: 140px; POSITION: absolute; HEIGHT: 120px"/DIV

CENTER

TABLE border=0

TBODY

TR

FORM name=xz

TD width=440 align=center vAlign=top bgcolor="#CCCCCC"

label122

textarea width=440 name="textarea"/textarea

/label

/FORM

FORM name=CLD

TD align=middle

TABLE width="300" border="0" cellSpacing=1 cellPadding=0

TR TBODY TR bgcolor="#319AFF"

TD colSpan=7 align="center"FONT style="FONT-SIZE: 9pt"

color=#9900CC size=3 公元

SELECT onchange=changeCld() name=years SCRIPT language=JavaScript for(i=1900;i2101;i++) document.write('option'+i)/SCRIPT /SELECT年

SELECT onchange=changeCld() name=months SCRIPT language=JavaScript for(i=1;i13;i++) document.write('option'+i) /SCRIPT /SELECT月

第 input name="s3" type="text" size="2" 个节气

SELECT name=hours SCRIPT language=JavaScript for(i=1;i13;i++) document.write('option'+i) /SCRIPT /SELECT时 /FONT TR align=middle bgColor=#FF9900

TD width=54FONT color=red日/FONTFONT color="#e7f7fe"SUN/FONT/TD

TD width=54一FONT color="#e7f7fe"MON/FONT/TD

TD width=54二FONT color="#e7f7fe"TUE/FONT/TD

TD width=54三FONT color="#e7f7fe"WED/FONT/TD

TD width=54四FONT color="#e7f7fe"THR/FONT/TD

TD width=54五FONT color="#e7f7fe"FRI/FONT/TD

TD width=54FONT color=green六/FONTFONT color="#e7f7fe"SAT/FONT/TD/TR

SCRIPT language=JavaScript!--

var gNum

for(i=0;i6;i++) {

document.write('tr align=center')

for(j=0;j7;j++) {

gNum = i*7+j

document.write('td id="GD' + gNum +'" onMouseOver="mOvr(' + gNum +')" onMouseOut="mOut()" onMouseDown="mDown(' + gNum +')"')

document.write('font id="SD' + gNum +'" size=5 face="Arial Black"')

if(j == 0) document.write(' color=red')

if(j == 6)

if(i%2==1) document.write(' color=red')

else document.write(' color=green')

document.write(' TITLE="" /fontbrfont id="LD' + gNum + '" size=2 style="font-size:9pt;" /font/td')

}

document.write('/tr')

}

//--/SCRIPT

/TBODY/TABLE/TD

TD width=60 align=middle vAlign=top bgcolor="#CCCCCC"BRBR P TR TD align=right bgColor=#00aa55 colSpan=8FONT color=#fffff face=宋体 id=GZ/FONT/TD/TR/TBODY/TABLE/TD/FORM/CENTER/TR/TBODY/TABLE/CENTER/BODY/HTML

如何用JavaScript编写一个万年历

html

head

base fptype="TRUE"

meta http-equiv="Content-Type" content="text/html; charset=gb2312"

title本地时间/title

scriptsetInterval("jnkc.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);/script

marquee scrollamount=8div id='jnkc'/div

/marquee

/head

body

script language=javascript

function settab()

{

var tab=document.getElementById('tab1');

//alert(se1.options[se1.selectedIndex].text)

var se11=se1.options[se1.selectedIndex].text;

var se21=se2.options[se2.selectedIndex].text;//下拉列表中的日期

//alert(se11+","+se21)

var lastday=new Date(se11,se21,0).getDate();//所选择月的天数

var firstday=new Date(se11,se21-1,1).getDay();//选择月的第一天是星期几

//alert(lastday+","+firstday)

var weekend;//每周的最后一天的日期

var lines;//第几行,相对于表格,星期为第零行

//第一行日期

for(var lin1=0;lin17;lin1++)

{

if(lin1firstday)

tab.rows[1].cells[lin1].innerHTML=" ";

else

if(lin1==0||lin1==6)

tab.rows[1].cells[lin1].innerHTML="font color=red"+(lin1-firstday+1)+"/font";

else

tab.rows[1].cells[lin1].innerHTML=lin1-firstday+1;

//alert(lin1+","+firstday)

weekend=lin1-firstday+1;

lines=1;//第一行

}

//将最后2行值空之后再添加数据,以免遗留上一个月的数据,二行相对于非闰年的二月份

for(var i=0;i7;i++)

{

tab.rows[5].cells[i].innerHTML=" ";

tab.rows[6].cells[i].innerHTML=" ";

}

while(weekendlastday)//循环到月末

{

for(var lin2=0;lin27;lin2++)

{

if(weekend+lin2lastday)//数字小于等于当前月的最后一天

{

if(lin2==0||lin2==6)

tab.rows[lines+1].cells[lin2].innerHTML="font color=red"+(weekend+1+lin2)+"/font";

else

tab.rows[lines+1].cells[lin2].innerHTML=weekend+1+lin2;

}

求论坛日历JS代码

我给你啊 。。。。。。。。。。~~~~~~~~~~~

function UncCalendar (sName, sDate)

{

/////////////////////////////////////////////////////////////////////////

//定义UncCalendar对象的属性并赋默认值。

//inputValue属性的值为"today"时表示(客户机)当前日期。

//直接在这里把默认值修改成你想要的,使用时你就什么也不用设置了。

this.inputName = sName || "uncDate";

this.inputValue = sDate || "";

this.inputSize = 10;

this.inputClass = "";

this.color = "#333333";

this.bgColor = "#EEEEEE";

this.buttonWidth = 60;

this.buttonWords = "选择日期";

this.canEdits = true;

this.hidesSelects = true;

/////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////

//定义display方法。

this.display = function ()

{

var reDate = /^(19[7-9]\d|20[0-5]\d)\-(0?\d|1[0-2])\-([0-2]?\d|3[01])$/;

if (reDate.test(this.inputValue))

{

var dates = this.inputValue.split("-");

var year = parseInt(dates[0], 10);

var month = parseInt(dates[1], 10);

var mday = parseInt(dates[2], 10);

}

else

{

var today = new Date();

var year = today.getFullYear();

var month = today.getMonth()+1;

var mday = today.getDate();

}

if (this.inputValue == "today")

inputValue = year + "-" + month + "-" + mday;

else

inputValue = this.inputValue;

var lastDay = new Date(year, month, 0);

lastDay = lastDay.getDate();

var firstDay = new Date(year, month-1, 1);

firstDay = firstDay.getDay();

var btnBorder =

"border-left:1px solid " + this.color + ";" +

"border-right:1px solid " + this.color + ";" +

"border-top:1px solid " + this.color + ";" +

"border-bottom:1px solid " + this.color + ";";

var btnStyle =

"padding-top:3px;cursor:default;width:" + this.buttonWidth + "px;text-align:center;height:18px;top:-9px;" +

"font:normal 12px 宋体;position:absolute;z-index:99;background-color:" + this.bgColor + ";" +

"line-height:12px;" + btnBorder + "color:" + this.color + ";";

var boardStyle =

"position:absolute;width:1px;height:1px;background:" + this.bgColor + ";top:8px;border:1px solid "+

this.color + ";display:none;padding:3px;";

var buttonEvent =

" onmouseover=\"this.childNodes[0].style.borderBottom='0px';" +

"this.childNodes[1].style.display='';this.style.zIndex=100;" +

(this.hidesSelects ?

"var slts=document.getElementsByTagName('SELECT');" +

"for(var i=0;islts.length;i++)slts[i].style.visibility='hidden';"

: "") + "\"" +

" onmouseout=\"this.childNodes[0].style.borderBottom='1px solid " + this.color + "';" +

"this.childNodes[1].style.display='none';this.style.zIndex=99;" +

(this.hidesSelects ?

"var slts=document.getElementsByTagName('SELECT');" +

"for(var i=0;islts.length;i++)slts[i].style.visibility='';"

: "") + "\"" +

" onselectstart=\"return false;\"";

var mdayStyle = "font:normal 9px Verdana,Arial,宋体;line-height:12px;cursor:default;color:" + this.color;

var weekStyle = "font:normal 12px 宋体;line-height:15px;cursor:default;color:" + this.color;

var arrowStyle = "font:bold 7px Verdana,宋体;cursor:hand;line-height:16px;color:" + this.color;

var ymStyle = "font:bold 12px 宋体;line-height:16px;cursor:default;color:" + this.color;

var changeMdays =

"var year=parseInt(this.parentNode.cells[2].childNodes[0].innerText);" +

"var month=parseInt(this.parentNode.cells[2].childNodes[2].innerText);" +

"var firstDay=new Date(year,month-1,1);firstDay=firstDay.getDay();" +

"var lastDay=new Date(year,month,0);lastDay=lastDay.getDate();" +

"var tab=this.parentNode.parentNode, day=1;" +

"for(var row=2;row8;row++)" +

" for(var col=0;col7;col++){" +

" if(row==2colfirstDay){" +

" tab.rows[row].cells[col].innerHTML=' ';" +

" tab.rows[row].cells[col].isDay=0;}" +

" else if(day=lastDay){" +

" tab.rows[row].cells[col].innerHTML=day;" +

" tab.rows[row].cells[col].isDay=1;day++;}" +

" else{" +

" tab.rows[row].cells[col].innerHTML='';" +

" tab.rows[row].cells[col].isDay=0;}" +

" }";

var pyEvent =

" onclick=\"var y=this.parentNode.cells[2].childNodes[0];y.innerText=parseInt(y.innerText)-1;" +

changeMdays + "\"";

var pmEvent =

" onclick=\"var y=this.parentNode.cells[2].childNodes[0];m=this.parentNode.cells[2].childNodes[2];" +

"m.innerText=parseInt(m.innerText)-1;if(m.innerText=='0'){m.innerText=12;y.innerText=" +

"parseInt(y.innerText)-1;}" + changeMdays + "\"";

var nmEvent =

" onclick=\"var y=this.parentNode.cells[2].childNodes[0];m=this.parentNode.cells[2].childNodes[2];" +

"m.innerText=parseInt(m.innerText)+1;if(m.innerText=='13'){m.innerText=1;y.innerText=" +

"parseInt(y.innerText)+1;}" + changeMdays + "\"";

var nyEvent =

" onclick=\"var y=this.parentNode.cells[2].childNodes[0];y.innerText=parseInt(y.innerText)+1;" +

changeMdays + "\"";

var mdayEvent =

" onmouseover=\"if(event.srcElement.tagName=='TD'event.srcElement.isDay){" +

"event.srcElement.style.backgroundColor='" + this.color + "';" +

"event.srcElement.style.color='" + this.bgColor + "';" +

"event.srcElement.style.cursor='hand';" +

"var ym=event.srcElement.parentNode.parentNode.rows[0].cells[2].childNodes;" +

"event.srcElement.title=ym[0].innerText+'-'+ym[2].innerText+'-'+event.srcElement.innerText;}\"" +

" onmouseout=\"if(event.srcElement.tagName=='TD'event.srcElement.isDay){" +

"event.srcElement.style.backgroundColor='" + this.bgColor + "';" +

"event.srcElement.style.color='" + this.color + "';" +

"event.srcElement.style.cursor='default';" +

"var ym=event.srcElement.parentNode.parentNode.rows[0].cells[2].childNodes;" +

"event.srcElement.title=ym[0].innerText+'-'+ym[2].innerText+'-'+event.srcElement.innerText;}\"" +

" onclick=\"if(event.srcElement.tagName=='TD'event.srcElement.isDay){" +

"var inp=this.parentNode.parentNode.parentNode.previousSibling.childNodes[0];" +

"inp.value=this.rows[0].cells[2].childNodes[0].innerText+'-'+this.rows[0].cells[2].childNodes[2]." +

"innerText+'-'+event.srcElement.innerText;" +

"this.parentNode.style.display='none';this.parentNode.parentNode.style.zIndex=99;" +

"this.parentNode.previousSibling.style.borderBottom='1px solid " + this.color + "';" +

(this.hidesSelects ?

"var slts=document.getElementsByTagName('SELECT');" +

"for(var i=0;islts.length;i++)slts[i].style.visibility='';"

: "") + "}\"";

var output = "";

output += "table cellpadding=0 cellspacing=1 style='display:inline;'tr";

output += " tdinput size=" + this.inputSize + " maxlength=10 value=\"" + inputValue + "\"";

output += (this.canEdits ? "" : " readonly") + " name=\"" + this.inputName + "\"/td";

output += " td width=" + this.buttonWidth + "";

output += " div style=\"position:absolute;overflow:visible;width:0px;height:0px;\"" + buttonEvent + "";

output += " div style=\"" + btnStyle + "\"nobr" + this.buttonWords + "/nobr/div";

output += " div style=\"" + boardStyle + "\"";

output += " table cellspacing=1 cellpadding=1 width=175" + mdayEvent + "";

output += " tr height=20 align=center";

output += " td style=\"" + arrowStyle + "\" title=\"上一年\"" + pyEvent + "/td";

output += " td style=\"" + arrowStyle + "\" align=left title=\"上个月\"" + pmEvent + "/td";

output += " td colspan=3 style=\"" + ymStyle + "\" valign=bottom";

output += " span" + year + "/spanspan年/spanspan" + month + "/spanspan月/span";

output += " /td";

output += " td style=\"" + arrowStyle + "\" align=right title=\"下个月\"" + nmEvent + "/td";

output += " td style=\"" + arrowStyle + "\" title=\"下一年\"" + nyEvent + "/td";

output += " /tr";

output += " tr height=20 align=center bgcolor=" + this.bgColor + "";

output += " td width=14% style=\"" + weekStyle + "\"日/td";

output += " td width=14% style=\"" + weekStyle + "\"一/td";

output += " td width=14% style=\"" + weekStyle + "\"二/td";

output += " td width=14% style=\"" + weekStyle + "\"三/td";

output += " td width=14% style=\"" + weekStyle + "\"四/td";

output += " td width=14% style=\"" + weekStyle + "\"五/td";

output += " td width=14% style=\"" + weekStyle + "\"六/td";

output += " /tr";

var day = 1;

for (var row=0; row6; row++)

{

output += "tr align=center";

for (var col=0; col7; col++)

{

if (row == 0 col firstDay)

output += "td style=\"" + mdayStyle + "\" /td";

else if (day = lastDay)

{

output += "td style=\"" + mdayStyle + "\" isDay=1" + day + "/td";

day++;

}

else

output += "td style=\"" + mdayStyle + "\"/td";

}

output += "/tr";

}

output += " /table";

output += " /div";

output += " /div";

output += " /td";

output += "/tr/table";

document.write(output);

}

/////////////////////////////////////////////////////////////////////////

}

超牛js版万年历源码,js制作万年历

本文目录一览: 1、万年历查询程序. C语言代码 2、JS万年历中如何求某天的节气 3、如何用JavaScript编写一个万年历 4、求论坛日历JS代码 万年历查询程序. C语言代码 除了天数差计算,

2023-12-08
php万年历带农历的,万年历转换农历公历

2023-01-06
java万年历,java万年历思路

2022-11-30
java万年历设置假期,java制作万年历

2022-11-18
java万年历,java万年历实训报告

2022-11-29
java万年历表(万年历java代码讲解)

2022-11-12
使用php写的一个万年历接口,php 万年历

2023-01-08
java万年历,java万年历课程设计

2022-11-22
c语言26万年历,C语言年历

2022-11-24
万年历的c语言,万年历c语言程序设计实验报告

2023-01-04
c语言课程设计简易万年历,C语言设计万年历

2023-01-05
农历时间js代码下载(js获取农历时间)

本文目录一览: 1、求一段JAVASCRIPT的时间显示代码, 2、农历转阳历JS代码 3、高手帮解决一个JS显示农历时间代码错误问题,真的很谢谢! 4、求js详细时间代码,年月日星期时分(秒),阴历

2023-12-08
日历设计文档用c语言编写万年历,c语言制作日历

2022-11-24
php日历控件(PHP制作日历)

2022-11-10
超酷水果忍者js网页版源代码的简单介绍

本文目录一览: 1、我有个mrp格式的水果忍者和iPhone4上的差不多不知道有高手能改成java的吗 2、iphone版水果忍者怎么修改杨桃数据?已经越狱了,求解 3、ipad腾讯视频错误代码301

2023-12-08
java三年工作以后的简历(java程序员的简历)

2022-11-12
代码之神js实战,狂神javascript笔记

2022-11-25
js超级闪闪小游戏代码(js小闪电)

本文目录一览: 1、求一javascript小游戏代码。【注:不要叫我去下载,你直接给我复制过来就可以了】。thank!! 2、js编写的小游戏有哪些 3、js编写小游戏控制子弹的移动,当第二颗子弹发

2023-12-08
js日历程序(原生js写日历)

2022-11-16
javascript高级教程的简单介绍

2022-11-14