js脚本 //==================================================== 参数设定部分 ======================================================= var bMoveable=true; //设置日历是否可以拖动 var _VersionInfo="" //版本信息
function nickWriteHead(yy,mm) //往 head 中写入当前的年与月 { odatelayer.nickYearHead.innerText = yy + " 年"; odatelayer.nickMonthHead.innerText = mm + " 月"; }
function tmpSelectYearInnerHTML(strYear) //年份的下拉框 { if (strYear.match(/\D/)!=null){alert("年份输入参数不是数字!");return;} var m = (strYear) ? strYear : new Date().getFullYear(); if (m < 1000 || m > 9999) {alert("年份值不在 1000 到 9999 之间!");return;} var n = m - 10; if (n < 1000) n = 1000; if (n + 26 > 9999) n = 9974; var s = ""; odatelayer.tmpSelectYearLayer.style.display=""; odatelayer.tmpSelectYearLayer.innerHTML = selectInnerHTML; odatelayer.tmpSelectYear.focus(); }
function tmpSelectMonthInnerHTML(strMonth) //月份的下拉框 { if (strMonth.match(/\D/)!=null){alert("月份输入参数不是数字!");return;} var m = (strMonth) ? strMonth : new Date().getMonth() + 1; var s = ""; odatelayer.tmpSelectMonthLayer.style.display=""; odatelayer.tmpSelectMonthLayer.innerHTML = selectInnerHTML; odatelayer.tmpSelectMonth.focus(); }
function closeLayer() //这个层的关闭 { document.all.nickDateLayer.style.display="none"; }
function IsPinYear(year) //判断是否闰平年 { if (0==year%4&&((year%100!=0)||(year%400==0))) return true;else return false; }
function GetMonthCount(year,month) //闰年二月为29天 { var c=MonHead[month-1];if((month==2)&&IsPinYear(year)) c++;return c; } function GetDOW(day,month,year) //求某天的星期几 { var dt=new Date(year,month-1,day).getDay()/7; return dt; }
function nickPrevY() //往前翻 Year { if(nickTheYear > 999 && nickTheYear <10000){nickTheYear--;} else{alert("年份超出范围(1000-9999)!");} nickSetDay(nickTheYear,nickTheMonth); } function nickNextY() //往后翻 Year { if(nickTheYear > 999 && nickTheYear <10000){nickTheYear++;} else{alert("年份超出范围(1000-9999)!");} nickSetDay(nickTheYear,nickTheMonth); } function nickToday() //Today Button { var today; nickTheYear = new Date().getFullYear(); nickTheMonth = new Date().getMonth()+1; if (nickTheMonth < 10){nickTheMonth = "0" + nickTheMonth;} today=new Date().getDate(); if (today < 10){today = "0" + today;} //nickSetDay(nickTheYear,nickTheMonth); if(outObject){ outObject.value=nickTheYear + "-" + nickTheMonth + "-" + today; } closeLayer(); } function nickPrevM() //往前翻月份 { if(nickTheMonth>1){nickTheMonth--}else{nickTheYear--;nickTheMonth=12;} nickSetDay(nickTheYear,nickTheMonth); } function nickNextM() //往后翻月份 { if(nickTheMonth==12){nickTheYear++;nickTheMonth=1}else{nickTheMonth++} nickSetDay(nickTheYear,nickTheMonth); }
function nickSetDay(yy,mm) //主要的写程序********** { nickWriteHead(yy,mm); //设置当前年月的公共变量为传入值 nickTheYear=yy; nickTheMonth=mm;
for (var i = 0; i < 39; i++){nickWDay[i]=""}; //将显示框的内容全部清空 var day1 = 1,day2=1,firstday = new Date(yy,mm-1,1).getDay(); //某月第一天的星期几 for (i=0;i for (i = firstday; day1 < GetMonthCount(yy,mm)+1; i++){nickWDay[i]=day1;day1++;} for (i=firstday+GetMonthCount(yy,mm);i<39;i++){nickWDay[i]=day2;day2++} for (i = 0; i < 39; i++) { var da = eval("odatelayer.nickDay"+i) //书写新的一个月的日期星期排列 if (nickWDay[i]!="") { //初始化边框 da.borderColorLight="#9496E1"; da.borderColorDark="#FFFFFF"; if(i { da.innerHTML="" + nickWDay[i] + ""; da.title=(mm==1?12:mm-1) +"月" + nickWDay[i] + "日"; da.onclick=Function("nickDayClick(this.innerText,-1)"); if(!outDate) da.style.backgroundColor = ((mm==1?yy-1:yy) == new Date().getFullYear() && (mm==1?12:mm-1) == new Date().getMonth()+1 && nickWDay[i] == new Date().getDate()) ? "#C6C7EF":"#E0E0E0"; else { da.style.backgroundColor =((mm==1?yy-1:yy)==outDate.getFullYear() && (mm==1?12:mm-1)== outDate.getMonth() + 1 && nickWDay[i]==outDate.getDate())? "#FFD700" : (((mm==1?yy-1:yy) == new Date().getFullYear() && (mm==1?12:mm-1) == new Date().getMonth()+1 && nickWDay[i] == new Date().getDate()) ? "#C6C7EF":"#E0E0E0"); //将选中的日期显示为凹下去 if((mm==1?yy-1:yy)==outDate.getFullYear() && (mm==1?12:mm-1)== outDate.getMonth() + 1 && nickWDay[i]==outDate.getDate()) { da.borderColorLight="#FFFFFF"; da.borderColorDark="#9496E1"; } } } else if (i>=firstday+GetMonthCount(yy,mm)) //下个月的部分 { da.innerHTML="" + nickWDay[i] + ""; da.title=(mm==12?1:mm+1) +"月" + nickWDay[i] + "日"; da.onclick=Function("nickDayClick(this.innerText,1)"); if(!outDate) da.style.backgroundColor = ((mm==12?yy+1:yy) == new Date().getFullYear() && (mm==12?1:mm+1) == new Date().getMonth()+1 && nickWDay[i] == new Date().getDate()) ? "#C6C7EF":"#E0E0E0"; else { da.style.backgroundColor =((mm==12?yy+1:yy)==outDate.getFullYear() && (mm==12?1:mm+1)== outDate.getMonth() + 1 && nickWDay[i]==outDate.getDate())? "#FFD700" : (((mm==12?yy+1:yy) == new Date().getFullYear() && (mm==12?1:mm+1) == new Date().getMonth()+1 && nickWDay[i] == new Date().getDate()) ? "#C6C7EF":"#E0E0E0"); //将选中的日期显示为凹下去 if((mm==12?yy+1:yy)==outDate.getFullYear() && (mm==12?1:mm+1)== outDate.getMonth() + 1 && nickWDay[i]==outDate.getDate()) { da.borderColorLight="#FFFFFF"; da.borderColorDark="#9496E1"; } } } else //本月的部分 { da.innerHTML="" + nickWDay[i] + ""; da.title=mm +"月" + nickWDay[i] + "日"; da.onclick=Function("nickDayClick(this.innerText,0)"); //给td赋予onclick事件的处理 //如果是当前选择的日期,则显示暗黄色的背景;如果是当前日期,则显示亮紫色的背景 if(!outDate) da.style.backgroundColor = (yy == new Date().getFullYear() && mm == new Date().getMonth()+1 && nickWDay[i] == new Date().getDate())? "#C6C7EF":"#E0E0E0"; else { da.style.backgroundColor =(yy==outDate.getFullYear() && mm== outDate.getMonth() + 1 && nickWDay[i]==outDate.getDate())? "#FFD700":((yy == new Date().getFullYear() && mm == new Date().getMonth()+1 && nickWDay[i] == new Date().getDate())? "#C6C7EF":"#E0E0E0"); //将选中的日期显示为凹下去 if(yy==outDate.getFullYear() && mm== outDate.getMonth() + 1 && nickWDay[i]==outDate.getDate()) { da.borderColorLight="#FFFFFF"; da.borderColorDark="#9496E1"; } } } da.style.cursor="hand" } else{da.innerHTML="";da.style.backgroundColor="";da.style.cursor="default"} } }
function nickDayClick(n,ex) //点击显示框选取日期,主输入函数************* { var yy=nickTheYear; var mm = parseInt(nickTheMonth)+ex; //ex表示偏移量,用于选择上个月份和下个月份的日期 //判断月份,并进行对应的处理 if(mm<1){ yy--; mm=12+mm; } else if(mm>12){ yy++; mm=mm-12; }
if (mm < 10){mm = "0" + mm;} if (outObject) { if (!n) {//outObject.value=""; return;} if ( n < 10){n = "0" + n;} outObject.value= yy + "-" + mm + "-" + n ; //注:在这里你可以输出改成你想要的格式 closeLayer(); } else {closeLayer(); alert("您所要输出的控件对象并不存在!");} }