中文(繁体)
<HTML> <HEAD> <TITLE>實用的中英文日曆網頁特效程式碼-downcodes.com</TITLE> <!--<script language="javascript" src="PopupCalendar.js" ></script>-- > <script> //更多來自downcodes.com function PopupCalendar(InstanceName) { ///全域標籤this.instanceName=InstanceName; ///屬性 this.separator="-" this.oBtnTodayTitle="今天" this.oBtnCancelTitle="取消" this.weekDaySting=new Array("S","M","T","W","T 」、「F」、「S」); this.monthSting=new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月" ,「十二月」);這個.寬度=200; this.currDate=new Date(); this.today=new Date(); this.startYear=1970; this.endYear=2010; ///CSS this.divBorderCss="1px 實心#BCD0DE"; this.tableBorderColor="#CCCCCC" ///方法 this.Init=CalendarInit; this.Fill=日曆填充; this.Refresh=日曆刷新; this.Restore=日曆復原; ///HTMLObject this.oTaget=null; this.oPreviousCell=null; this.sDIVID=實例名稱+"oDiv"; this.sTABLEID=實例名稱+"oTable"; this.sMONTHID=實例名稱+"oMonth"; this.sYEARID=實例名稱+"oYear"; } function CalendarInit() ///建立面板 { var sMonth,sYear sMonth=this.currDate.getMonth(); sYear=this.currDate.getYear(); htmlAll="<div id='"+this.sDIVID+"' style='display:none;position:absolute;寬度:"+this.Width+";邊框:"+this.divBorderCss+";padding:2px;background-顏色:#FFFFFF'>"; htmlAll+="<divalign='center'>"; /// 月 htmloMonth="<select id='"+this.sMONTHID+"' onchange=CalendarMonthChange("+this.instanceName+") style='width:50%'>"; for(i=0;i<12;i++) { htmloMonth+="<選項值='"+i+"'>"+this.monthSting[i]+"</選項>"; } hmoMonth+="</select>"; /// 年 htmloYear="<select id='"+this.sYEARID+"' onchange=CalendarYearChange("+this.instanceName+") style='width:50%'>"; for(i=this.startYear;i<=this.endYear;i++) { htmloYear+="<選項值='"+i+"'>"+i+"</選項>"; } HTMLoYear+="</select></div>"; /// 天 htmloDayTable="<table id='"+this.sTABLEID+"' width='100%' border=0 cellpadding=0 cellspacing=1 bgcolor='"+this.tableBorderColor+"'>"; HTMLoDayTable+="<tbody bgcolor='#ffffff'style='font-size:13px'>"; for(i=0;i<=6;i++) { if(i==0) htmloDayTable+="<tr bgcolor='#98B8CD'>";否則 HTMLoDayTable+="<tr>"; for(j=0;j<7;j++) { if(i==0) { htmloDayTable+="<td height='20'align='center' valign='middle' style='cursor:hand'>" ; htmloDayTable+=this.weekDaySting[j]+"</td>" } else { htmloDayTable+="<td height='20'align='center' valign='middle' style='cursor:hand'"; htmloDayTable+=" onmouseover=CalendarCellsMsOver("+this.instanceName+")"; htmloDayTable+=" onmouseout=CalendarCellsMsOut("+this.instanceName+")"; htmloDayTable+=" onclick=CalendarCellsClick(this,"+this.instanceName+")>"; HTMLoDayTable+="</td>" } } HTMLoDayTable+="</tr>"; } hmoDayTable+="</tbody></table>"; /// 今日按鈕 htmloButton="<divalign='center'style='padding:3px'>" htmloButton+="<button style='width:40%;border:1px Solid #BCD0DE;background-color:#eeeeee ; cursor:hand'" htmloButton+=" onclick=CalendarTodayClick("+this.instanceName+")>"+this.oBtnTodayTitle+"</button> " htmloButton+="<button style='width:40%;border:1px Solid # BCD0DEbutton style='width:40%;border:1px Solid # BCD0DEbutton style='width:40%;border:1px Solid # BCD0DE ;background-color:#eeeeee;cursor:hand'" htmloButton+=" onclick=CalendarCancel("+this.instanceName+")>"+this.oBtnCancelTitle+"</button> " htmloButton+="</div>" // /全部htmlAll=htmlAll+htmloMonth+htmloYear+htmloDayTable+htmloButton+"</div>";文檔.write(htmlAll); this.Fill(); } function CalendarFill() /// { var sMonth,sYear,sWeekDay,sToday,oTable,currRow,MaxDay,sDaySn,sIndex,rowIndex,cellIndex,oSelectMonth,oSelectYear sMonth=this.currDate.getMonth(urrDate.getMonth); sYear=this.currDate.getYear(); sWeekDay=(新日期(sYear,sMonth,1)).getDay(); sToday=this.currDate.getDate(); oTable=document.all[this.sTABLEID]; currRow=oTable.rows[1]; MaxDay=CalendarGetMaxDay(sYear,sMonth); oSelectMonth=document.all[this.sMONTHID] oSelectMonth.selectedIndex=sMonth; oSelectYear=document.all[this.sYEARID] for(i=0;i<oSelectYear.length;i++) { if(parseInt(oSelectYear.options[i].value)==sYear)oSelectYear.selectedIndex=i; } //// for(sDaySn=1,sIndex=sWeekDay;sIndex<=6;sDaySn++,sIndex++) { if(sDaySn==sToday) { currRow.cells[sIndex].innerHTML="<font color=red>< i><b>"+sDaySn+"</b></i></font>"; this.oPreviousCell=currRow.cells[sIndex]; } else { currRow.cells[sIndex].innerHTML=sDaySn; currRow.cells[sIndex].style.color="#666666"; CalendarCellSetCss(0,currRow.cells[sIndex]); } for(rowIndex=2;rowIndex<=6;rowIndex++) { if(sDaySn>MaxDay)break; currRow=oTable.rows[rowIndex]; for(cellIndex=0;cellIndex<currRow.cells.length;cellIndex++) { if(sDaySn==sToday) { currRow.cells[cellIndex].innerHTML="<font color=red><i><b>"+sDaySn+ “</b></i></font>”; this.oPreviousCell=currRow.cells[cellIndex]; } else { currRow.cells[cellIndex].innerHTML=sDaySn; currRow.cells[cellIndex].style.color="#666666"; CalendarCellSetCss(0,currRow.cells[cellIndex]); sDaySn++; if(sDaySn>MaxDay)break; } } } function CalendarRestore() /// 清除資料 { var oTable oTable=document.all[this.sTABLEID] for(i=1;i<oTable.rows.length;i++) { for(j=0;j< oTable.rows[i].cells.length;j++) { CalendarCellSetCss(0,oTable.rows[i].cells[j]); oTable.rows[i].cells[j].innerHTML=" "; } } } function CalendarRefresh(newDate) /// { this.currDate=newDate; this.Restore(); this.Fill(); } function CalendarCellsMsOver(oInstance) /// Cell MouseOver { var myCell myCell=event.srcElement; CalendarCellSetCss(0,oInstance.oPreviousCell);如果(myCell){ CalendarCellSetCss(1,myCell); oInstance.oPreviousCell=myCell; } } function CalendarCellsMsOut(oInstance) ////// Cell MouseOut { var myCell myCell=event.srcElement; CalendarCellSetCss(0,myCell); } 函數 CalendarCellsClick(oCell,oInstance) { var sDay,sMonth,sYear,newDate sYear=oInstance.currDate.getFullYear(); sMonth=oInstance.currDate.getMonth(); sDay=oInstance.currDate.getDate(); if(oCell.innerText!=" ") { sDay=parseInt(oCell.innerText); if(sDay!=oInstance.currDate.getDate()) { newDate=新日期(sYear,sMonth,sDay); oInstance.Refresh(newDate); sDateString=sYear+oInstance.separator+CalendarDblNum(sMonth+1)+oInstance.separator+CalendarDblNum(sDay); ///回傳sDateString if(oInstance.oTaget.tagName=="INPUT") { oInstance.oTaget.value=sDateString; } document.all[oInstance.sDIVID].style.display="none"; } function CalendarYearChange(oInstance) /// 年份更改 { var sDay,sMonth,sYear,newDate sDay=oInstance.currDate.getDate(); sMonth=oInstance.currDate.getMonth(); sYear=document.all[oInstance.sYEARID].value newDate=新日期(sYear,sMonth,sDay); oInstance.Refresh(newDate); } function CalendarMonthChange(oInstance) /// 月份變更 { var sDay,sMonth,sYear,newDate sDay=oInstance.currDate.getDate(); sMonth=document.all[oInstance.sMONTHID].value sYear=oInstance.currDate.getYear(); newDate=新日期(s年,s月,s日); oInstance.Refresh(newDate); } function CalendarTodayClick(oInstance) /// 「今天」按鈕 Change { oInstance.Refresh(new Date()); } function getDateString(oInputSrc,oInstance) { if(oInputSrc&&oInstance) { CalendarDiv=document.all[oInstance.sDIVID]; } oInstance.oTaget=oInputSrc; CalendarDiv.style.pixelLeft=CalendargetPos(oInputSrc,"左"); CalendarDiv.style.pixelTop=CalendargetPos(oInputSrc,"頂部")+oInputSrc.offsetHeight; CalendarDiv.style.display=(CalendarDiv.style.display=="無")?"":"無"; function CalendarCellSetCss(sMode,oCell) /// 設定單元格 CSS { // sMode // 0: OnMouserOut 1: OnMouseOver if(sMode) { oCell.style.border="1pxsolid #5589AA"; oCell.style.backgroundColor="#BCD0DE"; } else { oCell.style.border =“1px實體#FFFFFF”; oCell.style.backgroundColor="#FFFFFF"; function CalendarGetMaxDay(nowYear,nowMonth) /// 取得目前月份的 MaxDay { var nextMonth,nextYear,currDate,nextDate,theMaxDay nextMonth=nowMonth+1; if(nextMonth>11) { nextYear=nowYear+1;下個月=0; } else { nextYear=nowYear; currDate=新日期(nowYear,nowMonth,1); nextDate=新日期(nextYear,nextMonth,1); theMaxDay=(nextDate-currDate)/(24*60*60*1000);傳回最大天數; } function CalendargetPos(el,ePro) /// 取得絕對位置 { var ePos=0; while(el!=null) { ePos+=el["偏移量"+ePro]; el=el.offsetParent;返回 ePos; } function CalendarDblNum(num) { if(num<10) return "0"+num;否則返回數字; } function CalendarCancel(oInstance) ///取消 { CalendarDiv=document.all[oInstance.sDIVID]; CalendarDiv.style.display="無"; } </script> </head> <BODY> <script> var oCalendarEn=new PopupCalendar("oCalendarEn"); //初始化控制項時,請給出實例名稱如:oCalendarEn oCalendarEn.Init(); var oCalendarChs=new PopupCalendar("oCalendarChs"); //初始化控制項時,請給予實例名稱:oCalendarChs oCalendarChs.weekDaySting=new Array("日","一","二","三","四","五","六"); oCalendarChs.monthSting=new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"); oCalendarChs.oBtnTodayTitle="今天"; oCalendarChs.oBtnCancelTitle="取消"; oCalendarChs.Init(); </script> <br><br><br><br> <input readonly type="text" name="dd" id="aa" onClick="getDateString(this,oCalendarEn)" value="英文版" > <br><br><br><br> <input readonly type="text" name="dd" id="aa" onClick="getDateString(this,oCalendarChs)" value="中文介面版"> < /正文> </HTML>