ickWDay[i]=GetMonthCount(mm==1?yy-1:yy,mm==1?12:mm-1)-firstday+i+1 //上个月的最后几天 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<firstday) //上个月的部分 { da.innerHTML="<b><font color=gray>" + nickWDay[i] + "</font></b>"; 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="<b><font color=gray>" + nickWDay[i] + "</font></b>"; 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="<b>" + nickWDay[i] + "</b>"; 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("您所要输出的控件对象并不存在!");} } 前台调用方法 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <script language="javascript" src="./nickDate.js"></script> <title>无标题文档</title> </head> <body> <table width="100%" border="0"> <tr> <td><input name="Input" type="text" id="text1" onBlur="setday(this);" onClick="setday(this);" readonly="true" size="20"></td> </tr> </table> </body> </html>
上一页 [1] [2] [3] |