Skrip dengan perayaan dan kalendar lunar: Salin kod Kod adalah seperti berikut: 带农历的日历 <br> <!--<br /> var lunarInfo=Array baharu(<br /> 0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,<br /> 0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977,<br /> 0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970,<br /> 0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950,<br /> 0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557,<br /> 0x06ca0,0x0b550,0x15355,0x04da0,0x0a5d0,0x14573,0x052d0,0x0a9a8,0x0e950,0x06aa0,<br /> 0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0,<br /> 0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b5a0,0x195a6,<br /> 0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570,<br /> 0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0,<br /> 0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5,<br /> 0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930,<br /> 0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530,<br /> 0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45,<br /> 0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0)<br /> <br /> var solarMonth=Array baharu(31,28,31,30,31,30,31,31,30,31,30,31);<br /> var Animals=new Array("鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗", "猪");<br /> var solarTerm = new Array("小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种"夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降",立冬","小雪","大雇質","大鬇" ");<br /> var sTermInfo = Tatasusunan baharu(0,21208,42467,63836,85337,107014,128867,150921,173149,195551,218072,240693,263867,150921,173149,195551,218072,240693,263983,263983,335533,385 50,375494,397447,419210,440795,462224, 483532,504758);<br /> var nStr1 = new Array('日','一','二','三','四','五','六','七','八','九','十') ;<br /> var nStr2 = Tatasusunan baharu('初','十','廿','卅');<br /> //公历节日<br /> var sFtv = Tatasusunan baharu(<br /> "0101 元旦",<br /> "0214 情人节",<br /> "0308 妇女节",<br /> "0312 植树节",<br /> "0315 消费者权益日",<br /> "0401 愚人节",<br /> "0501 劳动节",<br /> "0504 青年节",<br /> "0512 护士节",<br /> "0601 儿童节",<br /> "0701 建党节",<br /> "0801 建军节",<br /> "0910 教师节",<br /> "0928 孔子诞辰",<br /> "1001 国庆节",<br /> "1006 老人节",<br /> "1024 联合国日",<br /> "1224 平安夜",<br /> "1225 圣诞节")<br /> //农历节日<br /> var lFtv = Tatasusunan baharu(<br /> "0101 春节",<br /> "0115 元宵节",<br /> "0505 端午节",<br /> "0707 七夕情人节",<br /> "0715 中元节",<br /> "0815 中秋节",<br /> "0909 重阳节",<br /> "1208 腊八节",<br /> "1224 小年")<br /> //返回农历y年的总天数<br /> fungsi lYearDays(y) {<br /> var i, jumlah = 348;<br /> for(i=0x8000; i>0x8; i>>=1)sum =(lunarInfo[y-1900]&i)?1:0;<br> return(jumlah leapDays(y));<br> }<br> //返回农历y年闰月的天数<br> fungsi leapDays(y) {<br> if(leapMonth(y)) return((lunarInfo[y-1900] & 0x10000)? 30: 29);<br> else return(0);<br> }<br> //判断y年的农历中那个月是闰月,不是闰月返回0<br> fungsi leapMonth(y){<br> return(lunarInfo[y-1900]&0xf);<br> }<br> //返回农历y年m月的总天数<br> fungsi bulanHari(y,m){<br> return((lunarInfo[y-1900]&(0x10000>>m))?30:29);<br> }<br> //算出当前月第一天的农历日期和当前农历日期下一个月农历的第一天日期<br> fungsi Dianaday(objDate) {<br> var i, lompat=0, suhu=0;<br> var baseDate = new Date(1900,0,31);<br> var offset = (objDate - baseDate)/86400000;<br> this.dayCyl = offset 40;<br> this.monCyl = 14;<br> untuk(i=1900; i<2050 && offset>0; i ) {<br> temp = lYearDays(i)<br> offset -= temp;<br> this.monCyl = 12;<br> }<br> if(offset<0) {<br /> offset = suhu;<br /> saya--;<br /> this.monCyl -= 12;<br /> }<br /> tahun ini = i;<br /> this.yearCyl=i-1864;<br /> lompat = lompatBulan(i); //闰哪个月<br /> this.isLeap = palsu;<br /> untuk(i=1; i<13 && mengimbangi>0; i ) {<br> if(leap>0 && i==(leap 1) && this.isLeap==false){ //闰月<br> --i; this.isLeap = benar; temp = leapDays(this.year);}<br> lain{<br> temp = monthDays(this.year, i);}<br> if(this.isLeap==true && i==(lompat 1)) this.isLeap = palsu; //解除闰月<br> offset -= temp;<br> if(this.isLeap == false) this.monCyl ;<br> }<br> if(offset==0 && lompat>0 && i==lompat 1)<br> if(this.isLeap){ this.isLeap = palsu;}<br> else{this.isLeap=true;--i;--this.monCyl;}<br> if(offset<0){offset =temp;--i;--this.monCyl;}<br /> this.month=i;<br /> this.day=offset 1;<br /> }<br /> //返回公历y年m 1月的天数<br /> fungsi solarDays(y,m){<br /> jika(m==1)<br /> return(((y%4==0)&&(y 0!=0)||(y@0==0))?29:28);<br /> lain<br /> return(solarMonth[m]);<br /> }<br /> //记录公历和农历某天的日期<br /> fungsi calElement(sYear,sBulan,sDay,week,lYear,lBulan,lDay,isLeap) {<br /> this.isToday = palsu;<br /> //公历<br /> this.sYear = sYear;<br /> this.sMonth = sMonth;<br /> this.sDay = sDay;<br /> this.week = minggu;<br /> //农历<br /> this.lYear = lYear;<br /> ini.lBulan = lBulan;<br /> this.lDay = lDay;<br /> this.isLeap = isLeap;<br /> //节日记录<br /> this.lunarFestival = ''; //农历节日<br /> this.solarFestival = ''; //公历节日<br /> this.solarTerms = ''; //节气<br /> }<br /> //返回某年的第n个节气为几日(从0小寒起算)<br /> fungsi sTerm(y,n) {<br /> var offDate = new Date((31556925974.7*(y-1900) sTermInfo[n]*60000) Date.UTC(1900,0,6,2,5));<br /> return(offDate.getUTCDate())<br /> }<br /> //保存y年m 1月的相关信息<br /> var fat=mat=9;<br /> var eve=0;<br /> kalendar fungsi(y,m) {<br /> lemak=mat=0;<br /> var sDObj,lDObj,lY,lM,lD=1,lL,lX=0,tmp1,tmp2;<br /> var lDPOS = Tatasusunan baharu(3);<br /> var n = 0;<br /> var firstLM = 0;<br /> sDObj = Tarikh baharu(y,m,1); //当月第一天的日期<br /> this.length = solarDays(y,m); //公历当月天数<br /> this.firstWeek = sDObj.getDay(); //公历当月1日星期几<br /> jika ((m 1)==5){fat=sDObj.getDay()}<br /> jika ((m 1)==6){mat=sDObj.getDay()}<br /> untuk(var i=0;i<ini.panjang;i ) {<br /> jika(lD>lX) {<br> sDObj = Tarikh baharu(y,m,i 1); //当月第一天的日期<br> lDObj = new Dianaday(sDObj); //农历<br> lY = lDObj.tahun; //农历年<br> lM = lDObj.bulan; //农历月<br> lD = lDObj.hari; //农历日<br> lL = lDObj.isLeap; //农历是否闰月<br> lX = lL? leapDays(lY): monthDays(lY,lM); //农历当月最後一天<br> jika (lM==12){eve=lX}<br> jika(n==0) dahuluLM = lM;<br> lDPOS[n ] = i-lD 1;<br> }<br> this[i] = new calElement(y,m 1,i 1,nStr1[(i this.firstWeek)%7],lY,lM,lD ,lL);<br> if((i this.firstWeek)%7==0){<br>Ini[i].warna = 'merah'; //warna Ahad<br> }<br> }<br> //Istilah solar<br> tmp1=sTerm(y,m*2)-1;<br> tmp2=sTerm(y,m*2 1)-1;<br> This[tmp1].solarTerms = solarTerm[m*2];<br> This[tmp2].solarTerms = solarTerm[m*2 1];<br> If((this.firstWeek 12)%7==5) //Black Friday<br> This[12].solarFestival = 'Black Friday';<br> Jika(y==tY && m==tM) ini[tD-1].isToday = true; }<br> //Paparkan tarikh kalendar lunar dalam bahasa Cina <br> fungsi cDay(d){<br> var s;<br> suis (d) {<br> kes 10:<br> s = 'Hari kesepuluh dalam bulan lunar'; kes 20:<br> s = 'dua puluh';<br> rehat;<br> kes 30:<br> s = 'tiga puluh'; rehat;<br> lalai:<br> s = nStr2[Math.floor(d/10)];<br> s = nStr1[d];<br> }<br> Pulangan;<br> }<br> var cld;<br> fungsi drawCld(SY,SM) {<br> var TF=benar;<br> var p1=p2="";<br> var i,sD,s,saiz;<br> cld = kalendar baharu(SY,SM);<br> GZ.innerHTML = ' ' Haiwan[(SY-4) ] ']'; //Zodiac<br> untuk(i=0;i<42;i ) {<br /> sObj=eval('SD' i);<br /> lObj=eval('LD' i);<br /> sObj.className = '';<br /> sD = i - cld.firstMinggu;<br /> If(sD>-1 && sD<cld.length) { //Dalam tarikh<br /> sObj.innerHTML = sD 1;<br /> If(cld[sD].isToday){ sObj.style.color = '#9900FF';} //Warna hari ini<br /> lain{sObj.style.color = '';}<br /> If(cld[sD].lDay==1){ //Paparkan bulan lunar<br /> lObj.innerHTML = '<b>' (cld[sD].isLeap?'Leap':'') cld[sD].lMonth 'month' (monthDays(cld[sD].lYear,cld[sD].lBulan )==29?'kecil':'besar') '</b>';<br> }<br> lain{lObj.innerHTML = cDay(cld[sD].lDay);} var Slfw=Ssfw=null;<br> s=cld[sD].solarFestival;<br> untuk (var ipp=0;ipp<lFtv.length;ipp ){ //Festival Lunar<br /> Jika (parseInt(lFtv[ipp].substr(0,2))==(cld[sD].lBulan)){<br /> Jika (parseInt(lFtv[ipp].substr(2,4))==(cld[sD].lDay)){<br /> lObj.innerHTML=lFtv[ipp].substr(5);<br /> Slfw=lFtv[ipp].substr(5);<br /> }<br /> }<br /> Jika (12==(cld[sD].lBulan)){ //Tentukan sama ada ia adalah Malam Tahun Baru<br /> Jika (malam==(cld[sD].lHari)){lObj.innerHTML="Malam Tahun Baru";Slfw="Malam Tahun Baru";}<br /> }<br /> }<br /> untuk (var ipp=0;ipp<sFtv.length;ipp ){ //Pesta kalendar Gregorian<br /> Jika (parseInt(sFtv[ipp].substr(0,2))==(SM 1)){<br /> Jika (parseInt(sFtv[ipp].substr(2,4))==(sD 1)){<br />lObj.innerHTML=sFtv[ipp].substr(5);<br /> Ssfw=sFtv[ipp].substr(5);<br /> }<br /> }<br /> }<br /> Jika ((SM 1)==5){ //Hari Ibu<br /> Jika (lemak==0){<br /> Jika ((sD 1)==7){Ssfw="Hari Ibu";lObj.innerHTML="Hari Ibu"}<br /> }<br /> jika tidak (gemuk<9){<br /> Jika ((sD 1)==((7-fat) 8)){Ssfw="Hari Ibu";lObj.innerHTML="Hari Ibu"}<br /> }<br /> }<br /> Jika ((SM 1)==6){ //Hari Bapa<br /> jika (mat==0){<br /> Jika ((sD 1)==14){Ssfw="Hari Bapa";lObj.innerHTML="Hari Bapa"}<br /> }<br /> jika tidak (mat<9){<br /> Jika ((sD 1)==((7-mat) 15)){Ssfw="Hari Bapa";lObj.innerHTML="Hari Bapa"}<br /> }<br /> }<br /> Jika (s.length<=0){ //Tetapkan warna istilah suria<br /> s=cld[sD].solarTerms;<br /> Jika(s.length>0) s = s.fontcolor('limegreen'); }<br> If(s.length>0) {lObj.innerHTML=s;Slfw=s;} //Istilah solar<br> Jika ((Slfw!=null)&&(Ssfw!=null)){<br> lObj.innerHTML=Slfw "/" Ssfw;<br> }<br> lain { //Bukan tarikh<br> sObj.innerHTML = '';<br> lObj.innerHTML = '';<br> }<br> }<br> }<br> //Apabila memilih tahun dan bulan dalam senarai juntai bawah, panggil fungsi tersuai drawCld() untuk memaparkan maklumat berkaitan kalendar Gregorian dan kalendar lunar<br> fungsi changeCld() {<br> var y,m;<br> y=CLD.SY.selectedIndex 1900;<br> m=CLD.SM.selectedIndex;<br> drawCld(y,m);<br> }<br> //Gunakan pembolehubah tersuai untuk menyimpan tahun, bulan dan hari dalam sistem semasa<br> var Today = new Date();<br> var tY = Today.getFullYear();<br> var tM = Today.getMonth();<br> var tD = Today.getDate();<br> //Apabila halaman dibuka, tahun dan bulan semasa dipaparkan dalam senarai juntai bawah, dan fungsi tersuai drawCld() dipanggil untuk memaparkan maklumat yang berkaitan dengan kalendar Gregorian dan lunar<br> function initial() {<br> CLD.SY.selectedIndex=tY-1900;<br> CLD.SM.selectedIndex=tM;<br> drawCld(tY,tM);<br> }<br> //--><br> </SKRIP> <BODY onload=initial()><br> <PUSAT><br> <FORM name=CLD><br> <JADUAL><br> <TR><br> <TD align=middle><br> <TABLE border=1 cellpadding="0" cellspacing="0" bordercolordark="#FFFFFF" bordercolor="#ffffff" bordercolorlight="#EEEEEE"><br> <TR bgcolor="#006600"><br> <TD colSpan=7><FONT color=#ffffff style="FONT-SIZE: 9pt">Kalendar Gregory <br> <SELECT name=SY onchange=changeCld() style="FONT-SIZE: 9pt"> <br> <SCRIPT language="JavaScript"><br> for(i=1900;i<2050;i ) document.write('<option>' i);<br> 年 <br> for(i=1;i<13;i ) document.write('<option>' i);<br> 月 日 一 二 三 四 五 六 <br> var gNum;<br> untuk(i=0;i<6;i ) {<br /> document.write('<tr align=center>');<br> untuk(j=0;j<7;j ) {<br /> gNum = i*7 j;<br /> document.write('<td id="GD' gNum '"><font id="SD' gNum '" size=2 face="Arial Black"');<br /> if(j == 0) document.write(' color=red');<br /> if(j == 6) document.write(' color=#000080');<br /> document.write(' TITLE=""> </font><br><font id="LD' gNum '" size=2 style="font-size:9pt"> </font> </td>');<br> }<br> document.write('</tr>');<br> }<br>