calendar2.js
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:27k
源码类别:

.net编程

开发平台:

C#

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