Home >Web Front-end >JS Tutorial >The calendar control is available for testing under FF2.0 and ie6_time and date
/***************************************************** *****
* Usage
* The control calls onclick="fPopCalendar(event,this,this)"
* As follows, set the control to readonly
* * size="15" onclick="fPopCalendar(event,this,this)"
* onfocus="this.select()" readonly=" readonly" />
* "
* " If the page is garbled, just put the following definition items containing Chinese characters into the page
****************** ****************************************/
var gMonths=new Array("January","February","March","April","May","June","July ","August","September","October","November","December");
var WeekDay=new Array("日","一","二" ,"三","四","五","六");
var strToday="Today";
var strYear="Year";
var strMonth="Month";
var strDay="day";
var splitChar="-";
var startYear=2000;
var endYear=2050;
var dayTdHeight=12;
var dayTdTextSize=12;
var gcNotCurMonth="#E0E0E0";
var gcRestDay="#FF0000";
var gcWorkDay="#444444";
var gcWeekDay="#990099";
var gcMouseOver= "#79D0FF";
var gcMouseOut="#F4F4F4";
var gcToday="#444444";
var gcTodayMouseOver="#6699FF";
var gcTodayMouseOut="#CCCCFF";
var gdCtrl=new Object();
var goSelectTag=new Array();
var gdCurDate=new Date();
var giYear=curYear=gdCurDate.getFullYear();
var giMonth=curMonth=gdCurDate.getMonth() 1;
var giDay=curDay=gdCurDate.getDate();
function $(){var elements=new Array();for(var i=0;i< arguments.length;i ) {var element=arguments[i];if(typeof(arguments[i])=='string'){element=document.getElementById(arguments[i]);}if(arguments.length= =1){return element;}elements.Push(element);}return elements;}
Array.prototype.Push=function(){var startLength=this.length;for(var i=0;i
String .prototype.cleanBlank=function(){return this.isEmpty()?"":this.replace(/s/g,"");}
function checkColor(){var color_tmp=(arguments[0] " ").replace(/s/g,"").toUpperCase();var model_tmp1=arguments[1].toUpperCase();var model_tmp2="rgb(" arguments[1].substring(1,3).HexToDec () "," arguments[1].substring(1,3).HexToDec() "," arguments[1].substring(5).HexToDec() ")";model_tmp2=model_tmp2.toUpperCase();if( color_tmp==model_tmp1 ||color_tmp==model_tmp2){return true;}return false;}
function $V(){return $(arguments[0]).value;}
function fPopCalendar(evt,popCtrl ,dateCtrl){evt.cancelBubble=true;gdCtrl=dateCtrl;var evtDate="";if(document.all){evtDate=evt.srcElement.value;}else{evtDate=evt.currentTarget.value;}var reg= /(^d{4})-([0-1]d)-([0-2]d$)/;if(reg.test(evtDate)){reg.exec();giYear=RegExp.$1 ;giMonth=RegExp.$2;giDay=RegExp.$3;}fSetYearMon(giYear,giMonth);var point=fGetXY(popCtrl);with($("calendardiv").style){left=point.x "px"; top=(point.y popCtrl.offsetHeight 1) "px";visibility='visible';zindex='99';position='absolute';}$("calendardiv").focus();}
function fSetDate(iYear,iMonth,iDay){var iMonthNew=new String(iMonth);var iDayNew=new String(iDay);if(iMonthNew.length<2){iMonthNew="0" iMonthNew;}if(iDayNew.length< 2){iDayNew="0" iDayNew;}gdCtrl.value=iYear splitChar iMonthNew splitChar iDayNew;fHideCalendar();}
function fHideCalendar(){$("calendardiv").style.visibility="hidden";for (var i=0;i
function Point(iX,iY){this.x=iX;this.y=iY ;}
function fBuildCal(iYear,iMonth){var aMonth=new Array();for(var i=1;i<7;i ){aMonth[i]=new Array(i);}var dCalDate=new Date(iYear,iMonth-1,1);var iDayOfFirst=dCalDate.getDay();var iDaysInMonth=new Date(iYear,iMonth,0).getDate();var iOffsetLast=new Date(iYear,iMonth-1,0).getDate()-iDayOfFirst 1;var iDate=1;var iNext=1;for(var d=0;d<7;d ){aMonth[1][d]=(d";for(var i=0;i<7;i ){dateCal =" ";for(var w=1;w<7;w ){dateCal ="" WeekDay[i] " ";}dateCal ="";for(var d=0;d<7;d ){var tmpid=w "" d;dateCal =" ";}return dateCal;} ";dateCal ="";dateCal =" ";}dateCal ="
function fUpdateCal(iYear,iMonth){var myMonth=fBuildCal(iYear,iMonth);var i=0;for(var w=1;w<7;w ){for(var d=0;d<7;d ){with($("cellText" w "" d)){parentNode.style.backgroundColor=gcMouseOut;parentNode.style.borderColor=gcMouseOut;parentNode.onmouseover=function(){this.style.backgroundColor=gcMouseOver;};parentNode.onmouseout=function(){this.style.backgroundColor=gcMouseOut;};if(myMonth[w][d]<0){style.color=gcNotCurMonth;innerHTML=Math.abs(myMonth[w][d]);}else{style.color=((d==0)||(d==6))?gcRestDay:gcWorkDay;innerHTML=myMonth[w][d];if(iYear==giYear && iMonth==giMonth && myMonth[w][d]==giDay){parentNode.style.backgroundColor=gcMouseOver;parentNode.onmouseover=function(){this.style.backgroundColor=gcMouseOver;};parentNode.onmouseout=function(){this.style.backgroundColor=gcMouseOver;};}if(iYear==curYear && iMonth==curMonth && myMonth[w][d]==curDay){style.color=gcToday;parentNode.style.backgroundColor=gcTodayMouseOut;parentNode.onmouseover=function(){this.style.backgroundColor=gcTodayMouseOver;};parentNode.onmouseout=function(){this.style.backgroundColor=gcTodayMouseOut;};}}}}}}
function fCurrentDate(){return curYear strYear curMonth strMonth curDay strDay;}
function fSetYearMon(iYear,iMon){$("tbSelMonth").options[iMon-1].selected=true;for(var i=0;i<$("tbSelYear").length;i ){if($("tbSelYear").options[i].value==iYear){$("tbSelYear").options[i].selected=true;}}fUpdateCal(iYear,iMon);}
function fPrevMonth(){var iMon=$("tbSelMonth").value;var iYear=$("tbSelYear").value;if(--iMon<1){iMon=12;iYear--;}fSetYearMon(iYear,iMon);}
function fNextMonth(){var iMon=$("tbSelMonth").value;var iYear=$("tbSelYear").value;if( iMon>12){iMon=1;iYear ;}fSetYearMon(iYear,iMon);}
function fGetXY(aTag){var oTmp=aTag;var pt=new Point(0,0);do{pt.x =oTmp.offsetLeft;pt.y =oTmp.offsetTop;oTmp=oTmp.offsetParent;}while(oTmp.tagName.toUpperCase()!="BODY");return pt;}
function getDateDiv(){var noSelectForIE="";var noSelectForFireFox="";if(document.all){noSelectForIE="onselectstart='return false;'";}else{noSelectForFireFox="-moz-user-select:none;";}var dateDiv="";dateDiv ="";dateDiv ="
";dateDiv =" ";dateDiv =" ";dateDiv =" ";dateDiv ="' style='height:20px;width:20px;font-weight:bolder;' onclick='fNextMonth()'>";dateDiv =" ";dateDiv ="";dateDiv =" ";dateDiv =" ";dateDiv ="";dateDiv =fDrawCal(giYear,giMonth,dayTdHeight,dayTdTextSize);dateDiv ="
";dateDiv ="";dateDiv ="" strToday ":" fCurrentDate() "";dateDiv ="
with(document){onclick=fHideCalendar;write(getDateDiv());}