Heim >Web-Frontend >js-Tutorial >日历控件在FF2.0,ie6下测试可用_时间日期

日历控件在FF2.0,ie6下测试可用_时间日期

WBOY
WBOYOriginal
2016-05-16 19:03:301199Durchsuche

/*********************************************************
 *     使用方法
 *         控件调用onclick="fPopCalendar(event,this,this)"
 *     如下,给控件设置为readonly
 *      *         size="15" onclick="fPopCalendar(event,this,this)" 
 *         onfocus="this.select()" readonly="readonly" />
 *     
 *     如果页面乱码,把下面包含汉字的定义项放到页面中即可
********************************************************/
var gMonths=new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");
var WeekDay=new Array("日","一","二","三","四","五","六");
var strToday="今天";
var strYear="年";
var strMonth="月";
var strDay="日";
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;iArray.prototype.Push=function(){var startLength=this.length;for(var i=0;iString.prototype.HexToDec=function(){return parseInt(this,16);}
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.lengthfunction fHideCalendar(){$("calendardiv").style.visibility="hidden";for(var i=0;ifunction fSetSelected(){var iOffset=0;var iYear=parseInt($("tbSelYear").value);var iMonth=parseInt($("tbSelMonth").value);var aCell=$("cellText"+arguments[0]);with(aCell){var iDay=parseInt(innerHTML);if(checkColor(style.color,gcNotCurMonth)){iOffset=(innerHTML>10)?-1:1;}iMonth+=iOffset;if(iMonth12){iYear++;iMonth=1;}}fSetDate(iYear,iMonth,iDay);}
function Point(iX,iY){this.x=iX;this.y=iY;}
function fBuildCal(iYear,iMonth){var aMonth=new Array();for(var i=1;ifunction fDrawCal(iYear,iMonth,iCellHeight,iDateTextSize){var colorTD="background-color:"+gcMouseOut+";border-color:"+gcMouseOut+";";var styleTD="height:"+iCellHeight+"px;font-weight:bolder;font-size:"+iDateTextSize+"px;vertical-align:middle; text-align:center;";var dateCal="";dateCal+="";for(var i=0;i"+WeekDay[i]+"";}dateCal+="";for(var w=1;w";for(var d=0;d";dateCal+="";dateCal+="";}dateCal+="";}return dateCal;}
function fUpdateCal(iYear,iMonth){var myMonth=fBuildCal(iYear,iMonth);var i=0;for(var w=1;wfunction fCurrentDate(){return curYear+strYear+curMonth+strMonth+curDay+strDay;}
function fSetYearMon(iYear,iMon){$("tbSelMonth").options[iMon-1].selected=true;for(var i=0;ifunction fPrevMonth(){var iMon=$("tbSelMonth").value;var iYear=$("tbSelYear").value;if(--iMonfunction 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+="";dateDiv+="";dateDiv+="
";dateDiv+=" ";dateDiv+=" ";dateDiv+="' style='height:20px;width:20px;font-weight:bolder;' onclick='fNextMonth()'>";dateDiv+="
";dateDiv+="
";dateDiv+=fDrawCal(giYear,giMonth,dayTdHeight,dayTdTextSize);dateDiv+="
";dateDiv+="
";dateDiv+=""+strToday+":"+fCurrentDate()+"";dateDiv+="
";return dateDiv;}
with(document){onclick=fHideCalendar;write(getDateDiv());}

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

日历控件.htm
复制代码 代码如下:


nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


日历控件_脚本之家





<script></script>


      




date.js
复制代码 代码如下:


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn