再来一个JS日历

先上图

代码:

Code:
  1. var bMoveable=true;   
  2. var strFrame;    
  3.   
  4. document.writeln('<iframe id=endDateLayer frameborder=0 style="position: absolute; z-index: 9998;width:162px;height:211px;display: none"></iframe>');   
  5. strFrame='<style>';   
  6. strFrame+='INPUT.button{BORDER-RIGHT: #63A3E9 1px solid;BORDER-TOP: #63A3E9 1px solid;BORDER-LEFT: #63A3E9 1px solid;';   
  7. strFrame+='BORDER-BOTTOM: #63A3E9 1px solid;BACKGROUND-COLOR: #63A3E9;font-family:宋体;}';   
  8. strFrame+='TD{FONT-SIZE: 9pt;font-family:宋体;}';   
  9. strFrame+='</style>';   
  10. strFrame+='<scr' + 'ipt>';   
  11. strFrame+='var datelayerx,datelayery;';   
  12. strFrame+='var bDrag;';   
  13. strFrame+='function document.onmousemove()';   
  14. strFrame+='{if(bDrag && window.event.button==1)';   
  15. strFrame+=' {var DateLayer=parent.document.all.endDateLayer.style;';   
  16. strFrame+=' DateLayer.posLeft += window.event.clientX-datelayerx;';   
  17. strFrame+=' DateLayer.posTop += window.event.clientY-datelayery;}}';   
  18. strFrame+='function DragStart()';   
  19. strFrame+='{var DateLayer=parent.document.all.endDateLayer.style;';   
  20. strFrame+=' datelayerx=window.event.clientX;';   
  21. strFrame+=' datelayery=window.event.clientY;';   
  22. strFrame+=' bDrag=true;}';   
  23. strFrame+='function DragEnd(){';   
  24. strFrame+=' bDrag=false;}';   
  25. strFrame+='</scr' + 'ipt>';   
  26. strFrame+='<div style="z-index:9999;position: absolute; left:0; top:0;" onselectstart="return false">';   
  27. strFrame+='<span id=tmpSelectYearLayer style="z-index: 9999;position: absolute;top: 3; left: 19;display: none"></span>';   
  28. strFrame+='<span id=tmpSelectMonthLayer style="z-index: 9999;position: absolute;top: 3; left: 78;display: none"></span>';   
  29. strFrame+='<span id=tmpSelectHourLayer style="z-index: 9999;position: absolute;top: 188; left: 35px;display: none"></span>';   
  30. strFrame+='<span id=tmpSelectMinuteLayer style="z-index:9999;position:absolute;top: 188; left: 77px;display: none"></span>';   
  31. strFrame+='<span id=tmpSelectSecondLayer style="z-index:9999;position:absolute;top: 188; left: 119px;display: none"></span>';   
  32. strFrame+='<table border=1 cellspacing=0 cellpadding=0 width=142 height=160 bordercolor=#63A3E9 bgcolor=#63A3E9 >';   
  33. strFrame+='    <tr><td width=142 height=23 bgcolor=#FFFFFF>';   
  34. strFrame+='        <table border=0 cellspacing=1 cellpadding=0 width=158 height=23>';   
  35. strFrame+='            <tr align=center >';   
  36. strFrame+='                <td width=16 align=center bgcolor=#63A3E9 style="font-size:12px;cursor: hand;color: #ffffff" ';   
  37. strFrame+='        οnclick="parent.meizzPrevM()" title="向前翻 1 月" ><b ><</b></td>';   
  38. strFrame+='       <td width=60 align="center" bgcolor="#63A3E9" style="font-size:12px;cursor:hand" ';   
  39. strFrame+='           οnmοuseοver="style.backgroundColor=/'#aaccf3/'"';   
  40. strFrame+='        οnmοuseοut="style.backgroundColor=/'#63A3E9/'" ';   
  41. strFrame+='        οnclick="parent.tmpSelectYearInnerHTML(this.innerText.substring(0,4))" ';   
  42. strFrame+='        title="点击这里选择年份"><span id=meizzYearHead></span></td>';   
  43. strFrame+='       <td width=48 align="center" style="font-size:12px;font-color: #ffffff;cursor:hand" ';   
  44. strFrame+='        bgcolor="#63A3E9" οnmοuseοver="style.backgroundColor=/'#aaccf3/'" ';   
  45. strFrame+='        οnmοuseοut="style.backgroundColor=/'#63A3E9/'" ';   
  46. strFrame+='        οnclick="parent.tmpSelectMonthInnerHTML(this.innerText.length==3?this.innerText.substring(0,1):this.innerText.substring(0,2))"';   
  47. strFrame+='        title="点击这里选择月份"><span id=meizzMonthHead ></span></td>';   
  48. strFrame+='       <td width=16 bgcolor=#63A3E9 align=center style="font-size:12px;cursor: hand;color: #ffffff" ';   
  49. strFrame+='        οnclick="parent.meizzNextM()" title="向后翻 1 月" ><b >></b></td>';   
  50. strFrame+='      </tr>';   
  51. strFrame+='     </table></td></tr>';   
  52. strFrame+='    <tr><td width=142 height=18 >';   
  53. strFrame+='     <table border=0 cellspacing=0 cellpadding=2 bgcolor=#63A3E9 ' + (bMoveable? 'οnmοusedοwn="DragStart()" οnmοuseup="DragEnd()"':'');   
  54. strFrame+='    BORDERCOLORLIGHT=#63A3E9 BORDERCOLORDARK=#FFFFFF width=140 height=20 style="cursor:' + (bMoveable ? 'move':'default') + '">';   
  55. strFrame+='    <tr><td style="font-size:12px;color:#ffffff" width=20> 日</td>';   
  56. strFrame+='<td style="font-size:12px;color:#FFFFFF" > 一</td><td style="font-size:12px;color:#FFFFFF"> 二</td>';   
  57. strFrame+='<td style="font-size:12px;color:#FFFFFF" > 三</td><td style="font-size:12px;color:#FFFFFF" > 四</td>';   
  58. strFrame+='<td style="font-size:12px;color:#FFFFFF" > 五</td><td style="font-size:12px;color:#FFFFFF" > 六</td></tr>';   
  59. strFrame+='</table></td></tr>';   
  60. strFrame+=' <tr ><td width=142 height=120 >';   
  61. strFrame+='    <table border=1 cellspacing=2 cellpadding=2 BORDERCOLORLIGHT=#63A3E9 BORDERCOLORDARK=#FFFFFF bgcolor=#fff8ec width=140 height=120 >';   
  62. var n=0; for (j=0;j<5;j++){ strFrame+= ' <tr align=center >'for (i=0;i<7;i++){   
  63. strFrame+='<td width=20 height=20 id=meizzDay'+n+' style="font-size:12px" οnclick=parent.meizzDayClick(this.innerText,0)></td>';n++;}   
  64. strFrame+='</tr>';}   
  65. strFrame+='      <tr align=center >';   
  66. for (i=35;i<37;i++)strFrame+='<td width=20 height=20 id=meizzDay'+i+' style="font-size:12px" οnclick="parent.meizzDayClick(this.innerText,0)"></td>';   
  67. strFrame+='        <td colspan=5 align=right style="color:#1478eb"><span οnclick="parent.setNull()" style="font-size:12px;cursor: hand"';   
  68. strFrame+='         οnmοuseοver="style.color=/'#ff0000/'" οnmοuseοut="style.color=/'#1478eb/'" title="将日期置空">置空</span>  <span οnclick="parent.meizzToday()" style="font-size:12px;cursor: hand"';   
  69. strFrame+='         οnmοuseοver="style.color=/'#ff0000/'" οnmοuseοut="style.color=/'#1478eb/'" title="当前日期时间">当前</span>  <span style="cursor:hand" id=evaAllOK οnmοuseοver="style.color=/'#ff0000/'" οnmοuseοut="style.color=/'#1478eb/'" οnclick="parent.closeLayer()" title="关闭日历">关闭 </span></td></tr>';   
  70. strFrame+='    </table></td></tr><tr ><td >';   
  71. strFrame+='        <table border=0 cellspacing=1 cellpadding=0 width=100% bgcolor=#FFFFFF height=22 >';   
  72. strFrame+='          <tr bgcolor="#63A3E9"><td id=bUseTimeLayer width=30 style="cursor:hand" title="点击这里启用/禁用时间"';   
  73. strFrame+='    οnmοuseοver="style.backgroundColor=/'#aaccf3/'" align=center οnmοuseοut="style.backgroundColor=/'#63A3E9/'"';   
  74. strFrame+='     οnclick="parent.UseTime(this)">';   
  75. strFrame+=' <span></span></td>';   
  76. strFrame+='             <td style="cursor:hand" οnclick="parent.tmpSelectHourInnerHTML(this.innerText.length==3?this.innerText.substring(0,1):this.innerText.substring(0,2))"';   
  77. strFrame+=' οnmοuseοver="style.backgroundColor=/'#aaccf3/'" οnmοuseοut="style.backgroundColor=/'#63A3E9/'"';   
  78. strFrame+=' title="点击这里选择时间" align=center width=42>' ;   
  79. strFrame+='     <span id=meizzHourHead></span></td>';   
  80. strFrame+='             <td style="cursor:hand" οnclick="parent.tmpSelectMinuteInnerHTML(this.innerText.length==3?this.innerText.substring(0,1):this.innerText.substring(0,2))"';   
  81. strFrame+=' οnmοuseοver="style.backgroundColor=/'#aaccf3/'" οnmοuseοut="style.backgroundColor=/'#63A3E9/'"';   
  82. strFrame+=' title="点击这里选择时间" align=center width=42>' ;   
  83. strFrame+='     <span id=meizzMinuteHead></span></td>';   
  84. strFrame+='             <td style="cursor:hand" οnclick="parent.tmpSelectSecondInnerHTML(this.innerText.length==3?this.innerText.substring(0,1):this.innerText.substring(0,2))"';   
  85. strFrame+=' οnmοuseοver="style.backgroundColor=/'#aaccf3/'" οnmοuseοut="style.backgroundColor=/'#63A3E9/'"';   
  86. strFrame+=' title="点击这里选择时间" align=center width=42>' ;   
  87. strFrame+='     <span id=meizzSecondHead></span></td>';   
  88. strFrame+='    </tr></table></td></tr></table></div>';   
  89.   
  90. window.frames.endDateLayer.document.writeln(strFrame);   
  91. window.frames.endDateLayer.document.close(); //解决ie进度条不结束的问题   
  92.   
  93.   
  94. //==================================================== WEB 页面显示部分 ======================================================   
  95. var outObject;   
  96. var outButton; //点击的按钮   
  97.   
  98. var outDate=""//存放对象的日期   
  99. var bUseTime=false//是否使用时间   
  100. var odatelayer=window.frames.endDateLayer.document.all; //存放日历对象   
  101. var odatelayer=window.endDateLayer.document.all;   
  102. //odatelayer.bUseTimeLayer.innerText="NO";   
  103. bImgSwitch();   
  104. odatelayer.bUseTimeLayer.innerHTML=bImg;   
  105.   
  106. function setday(tt,obj) //主调函数   
  107. {   
  108. if (arguments.length > 2){alert("对不起!传入本控件的参数太多!");return;}   
  109. if (arguments.length == 0){alert("对不起!您没有传回本控件任何参数!");return;}   
  110. var dads = document.all.endDateLayer.style;   
  111. var th = tt;   
  112. var ttop = tt.offsetTop; //TT控件的定位点高   
  113.   
  114. var thei = tt.clientHeight; //TT控件本身的高   
  115. var tleft = tt.offsetLeft; //TT控件的定位点宽   
  116.   
  117. var ttyp = tt.type; //TT控件的类型   
  118.   
  119. while (tt = tt.offsetParent){ttop+=tt.offsetTop; tleft+=tt.offsetLeft;}   
  120. dads.top = (ttyp=="image") ? ttop+thei : ttop+thei+6;   
  121. dads.left = tleft;   
  122. outObject = (arguments.length == 1) ? th : obj;   
  123. outButton = (arguments.length == 1) ? null : th; //设定外部点击的按钮   
  124.   
  125. //根据当前输入框的日期显示日历的年月   
  126. var reg = /^(/d+)-(/d{1,2})-(/d{1,2})/; //不含时间   
  127. var r = outObject.value.match(reg);   
  128. if(r!=null){   
  129. r[2]=r[2]-1;   
  130. var d=new Date(r[1],r[2],r[3]);   
  131. if(d.getFullYear()==r[1] && d.getMonth()==r[2] && d.getDate()==r[3])   
  132. {   
  133.    outDate=d;   
  134.    parent.meizzTheYear = r[1];   
  135.    parent.meizzTheMonth = r[2];   
  136.    parent.meizzTheDate = r[3];   
  137. }   
  138. else  
  139. {   
  140.    outDate="";   
  141. }   
  142. meizzSetDay(r[1],r[2]+1);   
  143. }   
  144. else  
  145. {   
  146. outDate="";   
  147. meizzSetDay(new Date().getFullYear(), new Date().getMonth() + 1);   
  148. }   
  149. dads.display = '';   
  150.   
  151. //判断初始化时是否使用时间,非严格验证   
  152. //if (outObject.value.length>10)   
  153. //{   
  154. bUseTime=false;   
  155. bImgSwitch();   
  156. odatelayer.bUseTimeLayer.innerHTML=bImg;   
  157. meizzWriteHead(meizzTheYear,meizzTheMonth);   
  158. //}   
  159. //else   
  160. //{   
  161. // bUseTime=false;   
  162. // bImgSwitch();   
  163. // odatelayer.bUseTimeLayer.innerHTML=bImg;   
  164. // meizzWriteHead(meizzTheYear,meizzTheMonth);   
  165. //}   
  166.   
  167. try  
  168. {   
  169. event.returnValue=false;   
  170. }   
  171. catch (e)   
  172. {   
  173. //此处排除错误,错误原因暂未找到。   
  174. }   
  175. }   
  176.   
  177. var MonHead = new Array(12); //定义阳历中每个月的最大天数   
  178.   
  179. MonHead[0] = 31; MonHead[1] = 28; MonHead[2] = 31; MonHead[3] = 30; MonHead[4] = 31; MonHead[5] = 30;   
  180. MonHead[6] = 31; MonHead[7] = 31; MonHead[8] = 30; MonHead[9] = 31; MonHead[10] = 30; MonHead[11] = 31;   
  181.   
  182. var meizzTheYear=new Date().getFullYear(); //定义年的变量的初始值   
  183.   
  184. var meizzTheMonth=new Date().getMonth()+1; //定义月的变量的初始值   
  185.   
  186. var meizzTheDate=new Date().getDate(); //定义日的变量的初始值    
  187. var meizzTheHour=new Date().getHours(); //定义小时变量的初始值   
  188.   
  189. var meizzTheMinute=new Date().getMinutes();//定义分钟变量的初始值   
  190. var meizzTheSecond=new Date().getSeconds();//定义秒变量的初始值   
  191.   
  192. var meizzWDay=new Array(37); //定义写日期的数组   
  193.   
  194. document.onclick = (function(){    
  195. with(window.event)   
  196. {   
  197. if (srcElement != outObject && srcElement != outButton)   
  198. closeLayer();   
  199. }   
  200. })   
  201.   
  202. document.onkeyup = (function(){   
  203. if (window.event.keyCode==27){   
  204. if(outObject)outObject.blur();   
  205. closeLayer();   
  206. }   
  207. else if(document.activeElement)   
  208. {   
  209. if(document.activeElement != outObject && document.activeElement != outButton)   
  210. {   
  211.    closeLayer();   
  212. }   
  213. }   
  214. })   
  215.   
  216. function meizzWriteHead(yy,mm,ss) //往 head 中写入当前的年与月   
  217. {   
  218. odatelayer.meizzYearHead.innerText = yy + " 年";   
  219. odatelayer.meizzMonthHead.innerText = format(mm) + " 月";   
  220. //插入当前小时、分   
  221. odatelayer.meizzHourHead.innerText=bUseTime?(meizzTheHour+" 时"):"";    
  222. odatelayer.meizzMinuteHead.innerText=bUseTime?(meizzTheMinute+" 分"):"";   
  223. odatelayer.meizzSecondHead.innerText=bUseTime?(meizzTheSecond+" 秒"):"";   
  224. }   
  225.   
  226. function tmpSelectYearInnerHTML(strYear) //年份的下拉框   
  227. {   
  228. if (strYear.match(//D/)!=null){alert("年份输入参数不是数字!");return;}   
  229. var m = (strYear) ? strYear : new Date().getFullYear();   
  230. if (m < 1000 || m > 9999) {alert("年份值不在 1000 到 9999 之间!");return;}   
  231. var n = m - 50;   
  232. if (n < 1000) n = 1000;   
  233. if (n + 101 > 9999) n = 9974;   
  234. var s = " <select name=tmpSelectYear style='font-size: 12px' "  
  235. s += "οnblur='document.all.tmpSelectYearLayer.style.display=/"none/"' "  
  236. s += "οnchange='document.all.tmpSelectYearLayer.style.display=/"none/";"  
  237. s += "parent.meizzTheYear = this.value; parent.meizzSetDay(parent.meizzTheYear,parent.meizzTheMonth)'>/r/n";   
  238. var selectInnerHTML = s;   
  239. for (var i = n; i < n + 101; i++)   
  240. {   
  241. if (i == m) { selectInnerHTML += "<option value='" + i + "' selected>" + i + "年" + "</option>/r/n"; }   
  242. else { selectInnerHTML += "<option value='" + i + "'>" + i + "年" + "</option>/r/n"; }   
  243. }   
  244. selectInnerHTML += "</select>";   
  245. odatelayer.tmpSelectYearLayer.style.display="";   
  246. odatelayer.tmpSelectYearLayer.innerHTML = selectInnerHTML;   
  247. odatelayer.tmpSelectYear.focus();   
  248. }   
  249.   
  250. function tmpSelectMonthInnerHTML(strMonth) //月份的下拉框   
  251. {   
  252. if (strMonth.match(//D/)!=null){alert("月份输入参数不是数字!");return;}   
  253. var m = (strMonth) ? strMonth : new Date().getMonth() + 1;   
  254. var s = "   <select name=tmpSelectMonth style='font-size: 12px' "  
  255. s += "οnblur='document.all.tmpSelectMonthLayer.style.display=/"none/"' "  
  256. s += "οnchange='document.all.tmpSelectMonthLayer.style.display=/"none/";"  
  257. s += "parent.meizzTheMonth = this.value; parent.meizzSetDay(parent.meizzTheYear,parent.meizzTheMonth)'>/r/n";   
  258. var selectInnerHTML = s;   
  259. for (var i = 1; i < 13; i++)   
  260. {   
  261. if (i == m) { selectInnerHTML += "<option value='"+i+"' selected>"+i+"月"+"</option>/r/n"; }   
  262. else { selectInnerHTML += "<option value='"+i+"'>"+i+"月"+"</option>/r/n"; }   
  263. }   
  264. selectInnerHTML += "</select>";   
  265. odatelayer.tmpSelectMonthLayer.style.display="";   
  266. odatelayer.tmpSelectMonthLayer.innerHTML = selectInnerHTML;   
  267. odatelayer.tmpSelectMonth.focus();   
  268. }   
  269.   
  270. /***** 增加 小时、分钟 ***/  
  271. function tmpSelectHourInnerHTML(strHour) //小时的下拉框   
  272. {   
  273. if (!bUseTime){return;}   
  274.   
  275. if (strHour.match(//D/)!=null){alert("小时输入参数不是数字!");return;}   
  276. var m = (strHour) ? strHour : new Date().getHours();   
  277. var s = "<select name=tmpSelectHour style='font-size: 12px' "  
  278. s += "οnblur='document.all.tmpSelectHourLayer.style.display=/"none/"' "  
  279. s += "οnchange='document.all.tmpSelectHourLayer.style.display=/"none/";"  
  280. s += "parent.meizzTheHour = this.value; parent.evaSetTime(parent.meizzTheHour,parent.meizzTheMinute);'>/r/n";   
  281. var selectInnerHTML = s;   
  282. for (var i = 0; i < 24; i++)   
  283. {   
  284. if (i == m) { selectInnerHTML += "<option value='"+i+"' selected>"+i+"</option>/r/n"; }   
  285. else { selectInnerHTML += "<option value='"+i+"'>"+i+"</option>/r/n"; }   
  286. }   
  287. selectInnerHTML += "</select>";   
  288. odatelayer.tmpSelectHourLayer.style.display="";   
  289. odatelayer.tmpSelectHourLayer.innerHTML = selectInnerHTML;   
  290. odatelayer.tmpSelectHour.focus();   
  291. }   
  292.   
  293. function tmpSelectMinuteInnerHTML(strMinute) //分钟的下拉框   
  294. {   
  295. if (!bUseTime){return;}   
  296.   
  297. if (strMinute.match(//D/)!=null){alert("分钟输入参数不是数字!");return;}   
  298. var m = (strMinute) ? strMinute : new Date().getMinutes();   
  299. var s = "<select name=tmpSelectMinute style='font-size: 12px' "  
  300. s += "οnblur='document.all.tmpSelectMinuteLayer.style.display=/"none/"' "  
  301. s += "οnchange='document.all.tmpSelectMinuteLayer.style.display=/"none/";"  
  302. s += "parent.meizzTheMinute = this.value; parent.evaSetTime(parent.meizzTheHour,parent.meizzTheMinute);'>/r/n";   
  303. var selectInnerHTML = s;   
  304. for (var i = 0; i < 60; i++)   
  305. {   
  306. if (i == m) { selectInnerHTML += "<option value='"+i+"' selected>"+i+"</option>/r/n"; }   
  307. else { selectInnerHTML += "<option value='"+i+"'>"+i+"</option>/r/n"; }   
  308. }   
  309. selectInnerHTML += "</select>";   
  310. odatelayer.tmpSelectMinuteLayer.style.display="";   
  311. odatelayer.tmpSelectMinuteLayer.innerHTML = selectInnerHTML;   
  312. odatelayer.tmpSelectMinute.focus();   
  313. }   
  314.   
  315. function tmpSelectSecondInnerHTML(strSecond) //秒的下拉框   
  316. {   
  317. if (!bUseTime){return;}   
  318.   
  319. if (strSecond.match(//D/)!=null){alert("分钟输入参数不是数字!");return;}   
  320. var m = (strSecond) ? strSecond : new Date().getMinutes();   
  321. var s = "<select name=tmpSelectSecond style='font-size: 12px' "  
  322. s += "οnblur='document.all.tmpSelectSecondLayer.style.display=/"none/"' "  
  323. s += "οnchange='document.all.tmpSelectSecondLayer.style.display=/"none/";"  
  324. s += "parent.meizzTheSecond = this.value; parent.evaSetTime(parent.meizzTheHour,parent.meizzTheMinute,parent.meizzTheSecond);'>/r/n";   
  325. var selectInnerHTML = s;   
  326. for (var i = 0; i < 60; i++)   
  327. {   
  328. if (i == m) { selectInnerHTML += "<option value='"+i+"' selected>"+i+"</option>/r/n"; }   
  329. else { selectInnerHTML += "<option value='"+i+"'>"+i+"</option>/r/n"; }   
  330. }   
  331. selectInnerHTML += "</select>";   
  332. odatelayer.tmpSelectSecondLayer.style.display="";   
  333. odatelayer.tmpSelectSecondLayer.innerHTML = selectInnerHTML;   
  334. odatelayer.tmpSelectSecond.focus();   
  335. }   
  336.   
  337. function closeLayer() //这个层的关闭   
  338. {   
  339. var o = document.getElementById("endDateLayer");   
  340. if (o != null)   
  341. {   
  342. o.style.display="none";   
  343. }   
  344. }   
  345.   
  346. function showLayer() //这个层的关闭   
  347. {   
  348. document.all.endDateLayer.style.display="";   
  349. }   
  350.   
  351. function IsPinYear(year) //判断是否闰平年   
  352. {   
  353. if (0==year%4&&((year%100!=0)||(year%400==0))) return true;else return false;   
  354. }   
  355.   
  356. function GetMonthCount(year,month) //闰年二月为29天   
  357. {   
  358. var c=MonHead[month-1];if((month==2)&&IsPinYear(year)) c++;return c;   
  359. }   
  360.   
  361. function GetDOW(day,month,year) //求某天的星期几   
  362. {   
  363. var dt=new Date(year,month-1,day).getDay()/7; return dt;   
  364. }   
  365.   
  366. function meizzPrevY() //往前翻 Year   
  367. {   
  368. if(meizzTheYear > 999 && meizzTheYear <10000){meizzTheYear--;}   
  369. else{alert("年份超出范围(1000-9999)!");}   
  370. meizzSetDay(meizzTheYear,meizzTheMonth);   
  371. }   
  372. function meizzNextY() //往后翻 Year   
  373. {   
  374. if(meizzTheYear > 999 && meizzTheYear <10000){meizzTheYear++;}   
  375. else{alert("年份超出范围(1000-9999)!");}   
  376. meizzSetDay(meizzTheYear,meizzTheMonth);   
  377. }   
  378. function setNull()   
  379. {   
  380. outObject.value = '';   
  381. closeLayer();   
  382. }   
  383. function meizzToday() //Today Button   
  384. {   
  385. parent.meizzTheYear = new Date().getFullYear();   
  386. parent.meizzTheMonth = new Date().getMonth()+1;   
  387. parent.meizzTheDate = new Date().getDate();   
  388. parent.meizzTheHour = new Date().getHours();   
  389. parent.meizzTheMinute = new Date().getMinutes();   
  390. parent.meizzTheSecond = new Date().getSeconds();   
  391. var meizzTheSecond = new Date().getSeconds();   
  392.   
  393. if (meizzTheMonth<10 && meizzTheMonth.length<2) //格式化成两位数字   
  394. {   
  395. parent.meizzTheMonth="0"+parent.meizzTheMonth;   
  396. }   
  397. if (parent.meizzTheDate<10 && parent.meizzTheDate.length<2) //格式化成两位数字   
  398. {   
  399. parent.meizzTheDate="0"+parent.meizzTheDate;   
  400. }   
  401. //meizzSetDay(meizzTheYear,meizzTheMonth);   
  402. if(outObject)   
  403. {   
  404. if (bUseTime)   
  405. {   
  406.    outObject.value= parent.meizzTheYear + "-" + format( parent.meizzTheMonth) + "-" +    
  407.        format(parent.meizzTheDate) + " " + format(parent.meizzTheHour) + ":" +    
  408.        format(parent.meizzTheMinute) + ":" + format(parent.meizzTheSecond);    
  409.        //注:在这里你可以输出改成你想要的格式   
  410. }   
  411. else  
  412. {   
  413.    outObject.value= parent.meizzTheYear + "-" + format( parent.meizzTheMonth) + "-" +    
  414.        format(parent.meizzTheDate); //注:在这里你可以输出改成你想要的格式   
  415. }   
  416. }   
  417. closeLayer();   
  418. }   
  419. function meizzPrevM() //往前翻月份   
  420. {   
  421. if(meizzTheMonth>1){meizzTheMonth--}else{meizzTheYear--;meizzTheMonth=12;}   
  422. meizzSetDay(meizzTheYear,meizzTheMonth);   
  423. }   
  424. function meizzNextM() //往后翻月份   
  425. {   
  426. if(meizzTheMonth==12){meizzTheYear++;meizzTheMonth=1}else{meizzTheMonth++}   
  427. meizzSetDay(meizzTheYear,meizzTheMonth);   
  428. }   
  429.   
  430. // TODO: 整理代码   
  431. function meizzSetDay(yy,mm) //主要的写程序**********   
  432. {   
  433. meizzWriteHead(yy,mm);   
  434. //设置当前年月的公共变量为传入值   
  435.   
  436. meizzTheYear=yy;   
  437. meizzTheMonth=mm;   
  438.   
  439. for (var i = 0; i < 37; i++){meizzWDay[i]=""}; //将显示框的内容全部清空   
  440.   
  441. var day1 = 1,day2=1,firstday = new Date(yy,mm-1,1).getDay(); //某月第一天的星期几   
  442.   
  443. for (i=0;i<firstday;i++)meizzWDay[i]=GetMonthCount(mm==1?yy-1:yy,mm==1?12:mm-1)-firstday+i+1 //上个月的最后几天   
  444.   
  445. for (i = firstday; day1 < GetMonthCount(yy,mm)+1; i++) { meizzWDay[i]=day1;day1++; }   
  446. for (i=firstday+GetMonthCount(yy,mm);i<37;i++) { meizzWDay[i]=day2;day2++; }   
  447. for (i = 0; i < 37; i++)   
  448. {   
  449. var da = eval("odatelayer.meizzDay"+i) //书写新的一个月的日期星期排列   
  450.   
  451. if (meizzWDay[i]!="")   
  452. {   
  453. //初始化边框   
  454. da.borderColorLight="#63A3E9";   
  455. da.borderColorDark="#63A3E9";   
  456. da.style.color="#1478eb";   
  457. if(i<firstday) //上个月的部分   
  458. {   
  459.    da.innerHTML="<b><font color=#BCBABC>" + meizzWDay[i] + "</font></b>";   
  460.    da.title=(mm==1?12:mm-1) +"月" + meizzWDay[i] + "日";   
  461.    da.οnclick=Function("meizzDayClick(this.innerText,-1)");   
  462.   
  463.    if(!outDate)   
  464.     da.style.backgroundColor = ((mm==1?yy-1:yy) == new Date().getFullYear() &&    
  465.      (mm==1?12:mm-1) == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate()) ?   
  466.       "#5CEFA0":"#f5f5f5";   
  467.    else  
  468.    {   
  469.     da.style.backgroundColor =((mm==1?yy-1:yy)==outDate.getFullYear() && (mm==1?12:mm-1)== outDate.getMonth() + 1 &&    
  470.     meizzWDay[i]==outDate.getDate())? "#84C1FF" :   
  471.     (((mm==1?yy-1:yy) == new Date().getFullYear() && (mm==1?12:mm-1) == new Date().getMonth()+1 &&    
  472.     meizzWDay[i] == new Date().getDate()) ? "#5CEFA0":"#f5f5f5");   
  473.     //将选中的日期显示为凹下去   
  474.   
  475.     if((mm==1?yy-1:yy)==outDate.getFullYear() && (mm==1?12:mm-1)== outDate.getMonth() + 1 &&    
  476.     meizzWDay[i]==outDate.getDate())   
  477.     {   
  478.      da.borderColorLight="#FFFFFF";   
  479.      da.borderColorDark="#63A3E9";   
  480.     }   
  481.    }   
  482. }   
  483. else if (i>=firstday+GetMonthCount(yy,mm)) //下个月的部分   
  484. {   
  485.    da.innerHTML="<b><font color=#BCBABC>" + meizzWDay[i] + "</font></b>";   
  486.    da.title=(mm==12?1:mm+1) +"月" + meizzWDay[i] + "日";   
  487.    da.οnclick=Function("meizzDayClick(this.innerText,1)");   
  488.    if(!outDate)   
  489.     da.style.backgroundColor = ((mm==12?yy+1:yy) == new Date().getFullYear() &&    
  490.      (mm==12?1:mm+1) == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate()) ?   
  491.       "#5CEFA0":"#f5f5f5";   
  492.    else  
  493.    {   
  494.     da.style.backgroundColor =((mm==12?yy+1:yy)==outDate.getFullYear() && (mm==12?1:mm+1)== outDate.getMonth() + 1 &&    
  495.     meizzWDay[i]==outDate.getDate())? "#84C1FF" :   
  496.     (((mm==12?yy+1:yy) == new Date().getFullYear() && (mm==12?1:mm+1) == new Date().getMonth()+1 &&    
  497.     meizzWDay[i] == new Date().getDate()) ? "#5CEFA0":"#f5f5f5");   
  498.     //将选中的日期显示为凹下去   
  499.   
  500.     if((mm==12?yy+1:yy)==outDate.getFullYear() && (mm==12?1:mm+1)== outDate.getMonth() + 1 &&    
  501.     meizzWDay[i]==outDate.getDate())   
  502.     {   
  503.      da.borderColorLight="#FFFFFF";   
  504.      da.borderColorDark="#63A3E9";   
  505.     }   
  506.    }   
  507. }   
  508. else //本月的部分   
  509.   
  510. {   
  511.    da.innerHTML="<b>" + meizzWDay[i] + "</b>";   
  512.    da.title=mm +"月" + meizzWDay[i] + "日";   
  513.    da.οnclick=Function("meizzDayClick(this.innerText,0)"); //给td赋予onclick事件的处理   
  514.   
  515.    //如果是当前选择的日期,则显示亮蓝色的背景;如果是当前日期,则显示暗黄色背景   
  516.    if(!outDate)   
  517.     da.style.backgroundColor = (yy == new Date().getFullYear() && mm == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate())?   
  518.      "#5CEFA0":"#f5f5f5";   
  519.    else  
  520.    {   
  521.     da.style.backgroundColor =(yy==outDate.getFullYear() && mm== outDate.getMonth() + 1 && meizzWDay[i]==outDate.getDate())?   
  522.      "#84C1FF":((yy == new Date().getFullYear() && mm == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate())?   
  523.      "#5CEFA0":"#f5f5f5");   
  524.     //将选中的日期显示为凹下去   
  525.   
  526.     if(yy==outDate.getFullYear() && mm== outDate.getMonth() + 1 && meizzWDay[i]==outDate.getDate())   
  527.     {   
  528.      da.borderColorLight="#FFFFFF";   
  529.      da.borderColorDark="#63A3E9";   
  530.     }   
  531.    }   
  532. }   
  533.     da.style.cursor="hand"  
  534.    }   
  535. else { da.innerHTML="";da.style.backgroundColor="";da.style.cursor="default"; }   
  536. }   
  537. }   
  538.   
  539. function meizzDayClick(n,ex) //点击显示框选取日期,主输入函数*************   
  540. {   
  541. parent.meizzTheDate=n;   
  542. var yy=meizzTheYear;   
  543. var mm = parseInt(meizzTheMonth)+ex; //ex表示偏移量,用于选择上个月份和下个月份的日期   
  544. var hh=meizzTheHour;   
  545. var mi=meizzTheMinute;   
  546. var se=meizzTheSecond;   
  547. //判断月份,并进行对应的处理   
  548.   
  549. if(mm<1){   
  550. yy--;   
  551. mm=12+mm;   
  552. }   
  553. else if(mm>12){   
  554. yy++;   
  555. mm=mm-12;   
  556. }   
  557.   
  558. if (mm < 10) {mm = "0" + mm;}   
  559. if (hh<10) {hh="0" + hh;} //时   
  560. if (mi<10) {mi="0" + mi;} //分   
  561. if (se<10) {se="0" + se;} //秒   
  562.   
  563. if (outObject)   
  564. {   
  565. if (!n) { //outObject.value="";    
  566.    return;}   
  567. if ( n < 10){n = "0" + n;}   
  568.   
  569. WriteDateTo(yy,mm,n,hh,mi,se);   
  570.   
  571. closeLayer();    
  572. if (bUseTime)   
  573. {   
  574.    try  
  575.    {   
  576.     outButton.click();   
  577.    }   
  578.    catch (e)   
  579.    {   
  580.     setday(outObject);   
  581.    }   
  582. }   
  583. }   
  584. else {closeLayer(); alert("您所要输出的控件对象并不存在!");}   
  585. closeLayer();    
  586. }   
  587.   
  588. function format(n) //格式化数字为两位字符表示   
  589. {   
  590. var m=new String();   
  591. var tmp=new String(n);   
  592. if (n<10 && tmp.length<2)   
  593. {   
  594. m="0"+n;   
  595. }   
  596. else  
  597. {   
  598. m=n;   
  599. }   
  600. return m;   
  601. }   
  602.   
  603. function evaSetTime() //设置用户选择的小时、分钟   
  604. {   
  605. odatelayer.meizzHourHead.innerText=meizzTheHour+" 时";   
  606. odatelayer.meizzMinuteHead.innerText=meizzTheMinute+" 分";   
  607. odatelayer.meizzSecondHead.innerText=meizzTheSecond+" 秒";   
  608. WriteDateTo(meizzTheYear,meizzTheMonth,meizzTheDate,meizzTheHour,meizzTheMinute,meizzTheSecond)   
  609. }   
  610.   
  611. function evaSetTimeNothing() //设置时间控件为空   
  612. {   
  613. odatelayer.meizzHourHead.innerText="";   
  614. odatelayer.meizzMinuteHead.innerText="";   
  615. odatelayer.meizzSecondHead.innerText="";   
  616. WriteDateTo(meizzTheYear,meizzTheMonth,meizzTheDate,meizzTheHour,meizzTheMinute,meizzTheSecond)   
  617. }   
  618.   
  619. function evaSetTimeNow() //设置时间控件为当前时间   
  620. {   
  621. odatelayer.meizzHourHead.innerText=new Date().getHours()+" 时";   
  622. odatelayer.meizzMinuteHead.innerText=new Date().getMinutes()+" 分";   
  623. odatelayer.meizzSecondHead.innerText=new Date().getSeconds()+" 秒";   
  624. meizzTheHour = new Date().getHours();   
  625. meizzTheMinute = new Date().getMinutes();   
  626. meizzTheSecond = new Date().getSeconds();   
  627. WriteDateTo(meizzTheYear,meizzTheMonth,meizzTheDate,meizzTheHour,meizzTheMinute,meizzTheSecond)   
  628. }   
  629.   
  630. function UseTime(ctl)   
  631. {   
  632. bUseTime=!bUseTime;   
  633. if (bUseTime)   
  634. {   
  635. bImgSwitch();   
  636. ctl.innerHTML=bImg;   
  637. evaSetTime(); //显示时间,用户原来选择的时间   
  638. //evaSetTimeNow(); //显示当前时间   
  639. }   
  640. else  
  641. {   
  642. bImgSwitch();   
  643. ctl.innerHTML=bImg;   
  644. evaSetTimeNothing();   
  645. }   
  646. }   
  647.   
  648. function WriteDateTo(yy,mm,n,hh,mi,se)   
  649. {   
  650. if (bUseTime)   
  651. {   
  652. outObject.value= yy + "-" + format(mm) + "-" + format(n) + " " + format(hh) + ":" + format(mi) + ":" + format(se); //注:在这里你可以输出改成你想要的格式   
  653. //outObject.value= yy + "-" + format(mm) + "-" + format(n);   
  654. }   
  655. else  
  656. {   
  657. outObject.value= yy + "-" + format(mm) + "-" + format(n); //注:在这里你可以输出改成你想要的格式   
  658. }   
  659. }   
  660.   
  661. function bImgSwitch()   
  662. {   
  663. if (bUseTime)   
  664. {   
  665. bImg="开启";   
  666. }   
  667. else  
  668. {   
  669. bImg="关闭";   
  670. }   
  671. }  

使用方法:

主调用函数是 setday(this,[object])和setday(this),[object]是控件输出的控件名,举两个例子:
 一、<input name=txt><input type=button value=setday οnclick="setday(this,document.all.txt)">
 二、<input οnfοcus="setday(this)">
 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 29
    评论
YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 29
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值