ホームページ > 記事 > ウェブフロントエンド > カレンダー コントロールは、FF2.0 および ie6_time and date でのテストに使用できます。
/*************************************************** * *****
* 使用法
* コントロールは onclick="fPopCalendar(event,this,this)" を呼び出します
* 以下のように、コントロールを読み取り専用に設定します
* <入力タイプ=" text" style="border:1px Solid #cccccc;"
* size="15" onclick="fPopCalendar(event,this,this)"
* onfocus="this.select()" readonly =" readonly" />
* "
* " ページ内に以下の漢字を含む定義項目を入れてください
************ **** ***************************************/
var gMonths=new Array("1 月","2 月","3 月","4 月","5 月","6 月","7 月 ","8 月"," September","10 月","11 月","12 月");
var WeekDay=new Array("日","一","二" ,"三","四","五","六");
var strToday="今日";
var stryear="年";
var strMonth="月";
var strDay="日";
var splitChar= "-";
var start Year=2050;
var dayTdTextSize=12; var gcRestDay="#FF0000";
var gcWorkDay="#990099";
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 giMonth=curMonth=gdCurDate.getMonth(); var giDay=curDay=gdCurDate.getDate();
function $(){var elements=new Array();for(var i=0;i< argument.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) ;}要素を返す;}
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(" argument[1].substring(1,3).HexToDec () "," argument[1].substring(1, 3).HexToDec() "," argument[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();gi Year=RegExp.$1 ;giMonth=RegExp.$2;giDay=RegExp.$3;} fSet YearMon(gi Year,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 =i Year SplitChar iMonthNew SplitChar iDayNew;fHideCalendar();}
function fHideCalendar(){$("calendardiv").style.visibility="hidden";for (var i=0;i
function fBuildCal(iyear,iMonth){var aMonth=新しい配列();for(var i=1;ifunction fUpdateCal(i Year,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(i Year==gi Year && 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(i Year==cur Year && 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;};} }}}}}
関数 fCurrentDate(){return curyear stryear curMonth strMonth curDay strDay;}
function fSet YearMon(i Year,iMon){$("tbSelMonth").options[iMon-1].selected=true ;for(var i=0;i<$("tbSel Year").length;i ){if($("tbSel Year").options[i].value==i Year){$("tbSel Year").options [i].selected=true;}}fUpdateCal(i Year,iMon);}
function fPrevMonth(){var iMon=$("tbSelMonth").value;var i Year=$("tbSel Year").value; if(--iMon<1){iMon=12;i Year--;}fSet YearMon(i Year,iMon);}
function fNextMonth(){var iMon=$("tbSelMonth").value;var i Year=$ ("tbSelyear").value;if( iMon>12){iMon=1;i Year ;}fSet YearMon(i Year,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='高さ:20px;幅:20px;フォントの太さ:太字;' onclick='fNextMonth()'>";dateDiv =" ";dateDiv ="";dateDiv =" ";dateDiv =" ";dateDiv ="" ;dateDiv =fDrawCal(gi Year,giMonth,dayTdHeight,dayTdTextSize);dateDiv ="
";dateDiv ="" strToday ":" fCurrentDate() "";dateDiv =" ";dateDiv ="
with(document){onclick=fHideCalendar;write(getDateDiv());}