/* powered by ly200.com http://www.ly200.com 广州联雅网络科技有限公司 020-83226791 */ var cal; var isfocus=false; //是否为焦点 function selectdate(obj){ var date=new date(); var by=date.getfullyear()-10; //最小值 → 10 年前 var ey=date.getfullyear()+10; //最大值 → 10 年后 cal=(cal==null)?new calendar(by, ey):cal; cal.show(obj); } string.prototype.todate=function(style){ var y=this.substring(style.indexof('y'),style.lastindexof('y')+1);//年 var m=this.substring(style.indexof('m'),style.lastindexof('m')+1);//月 var d=this.substring(style.indexof('d'),style.lastindexof('d')+1);//日 if(isnan(y)) y=new date().getfullyear(); if(isnan(m)) m=new date().getmonth(); if(isnan(d)) d=new date().getdate(); var dt ; eval("dt=new date('"+y+"', '"+(m-1)+"', '"+d+"')"); return dt; } date.prototype.format=function(style){ var o={ 'm+':this.getmonth()+1, //month 'd+':this.getdate(), //day 'h+':this.gethours(), //hour 'm+':this.getminutes(), //minute 's+':this.getseconds(), //second 'w+':''.charat(this.getday()), //week 'q+':math.floor((this.getmonth()+3) / 3), //quarter 's':this.getmilliseconds() //millisecond } if(/(y+)/.test(style)){ style=style.replace(regexp.$1, (this.getfullyear()+'').substr(4-regexp.$1.length)); } for(var k in o){ if(new regexp('('+ k +')').test(style)){ style=style.replace(regexp.$1, regexp.$1.length==1?o[k] : ('00'+o[k]).substr((''+o[k]).length)); } } return style; }; /* * 日历类 * @param beginyear 1990 * @param endyear 2010 * @param dateformatstyle 'yyyy-mm-dd'; */ function calendar(beginyear, endyear){ this.beginyear=1990; this.endyear=2010; this.dateformatstyle='yyyy-mm-dd'; if(beginyear!=null && endyear!=null){ this.beginyear=beginyear; this.endyear=endyear; } this.datecontrol=null; this.panel=this.getelementbyid('calendarpanel'); this.container=this.getelementbyid('containerpanel'); this.form=null; this.date=new date(); this.year=this.date.getfullyear(); this.month=this.date.getmonth(); this.colors={ 'cur_word' :'#ffffff', //当日日期文字颜色 'cur_bg' :'#83a6f4', //当日日期单元格背影色 'sel_bg' :'#ffcccc', //已被选择的日期单元格背影色 'sun_word' :'#ff0000', //星期天文字颜色 'sat_word' :'#0000ff', //星期六文字颜色 'td_word_light':'#333333', //单元格文字颜色 'td_word_dark' :'#cccccc', //单元格文字暗色 'td_bg_out' :'#efefef', //单元格背影色 'td_bg_over' :'#ffcc00', //单元格背影色 'tr_word' :'#ffffff', //日历头文字颜色 'tr_bg' :'#666666', //日历头背影色 'input_border' :'#cccccc', //input控件的边框颜色 'input_bg' :'#efefef' //input控件的背影色 } this.draw(); this.bindyear(); this.bindmonth(); this.changeselect(); this.binddata(); } calendar.prototype.draw=function(){ calendar=this; var mvary=[]; mvary[mvary.length]='
'; mvary[mvary.length]=' '; mvary[mvary.length]=' '; mvary[mvary.length]=' '; mvary[mvary.length]=' '; mvary[mvary.length]=' '; mvary[mvary.length]=' '; mvary[mvary.length]='
'; mvary[mvary.length]=' '; mvary[mvary.length]=' '; for(var i=0; i<7; i++){ mvary[mvary.length]=' '; } mvary[mvary.length]=' '; for(var i=0; i<6;i++){ mvary[mvary.length]=' '; for(var j=0; j<7; j++){ if(j==0){ mvary[mvary.length]=' '; }else if(j==6){ mvary[mvary.length]=' '; }else{ mvary[mvary.length]=' '; } } mvary[mvary.length]=' '; } mvary[mvary.length]=' '; mvary[mvary.length]=' '; mvary[mvary.length]=' '; mvary[mvary.length]=' '; mvary[mvary.length]=' '; mvary[mvary.length]='
'+eval('ly200jslang._date._weeks._'+i)+'
'; mvary[mvary.length]='
'; this.panel.innerhtml=mvary.join(''); var obj=this.getelementbyid('prevmonth'); obj.onclick=function (){calendar.goprevmonth(calendar);} obj.onblur=function (){calendar.onblur();} this.prevmonth= obj; obj=this.getelementbyid('nextmonth'); obj.onclick=function (){calendar.gonextmonth(calendar);} obj.onblur=function (){calendar.onblur();} this.nextmonth= obj; obj=this.getelementbyid('calendarclear'); obj.onclick=function (){calendar.datecontrol.value='';calendar.hide();} this.calendarclear=obj; obj=this.getelementbyid('calendarclose'); obj.onclick=function (){calendar.hide();} this.calendarclose=obj; obj=this.getelementbyid('calendaryear'); obj.onchange=function (){calendar.update(calendar);} obj.onblur=function (){calendar.onblur();} this.calendaryear=obj; obj=this.getelementbyid('calendarmonth'); with(obj) { onchange=function (){calendar.update(calendar);} onblur=function (){calendar.onblur();} }this.calendarmonth=obj; obj=this.getelementbyid('calendartoday'); obj.onclick=function (){ var today=new date(); calendar.date=today; calendar.year=today.getfullyear(); calendar.month=today.getmonth(); calendar.changeselect(); calendar.binddata(); calendar.datecontrol.value=today.format(calendar.dateformatstyle); calendar.hide(); } this.calendartoday=obj; } //年份下拉框绑定数据 calendar.prototype.bindyear=function(){ var cy=this.calendaryear; cy.length=0; for(var i=this.beginyear; i <= this.endyear; i++){ cy.options[cy.length]=new option(i, i); } } //月份下拉框绑定数据 calendar.prototype.bindmonth=function(){ var cm=this.calendarmonth; cm.length=0; for(var i=0; i<12; i++){ cm.options[cm.length]=new option(eval('ly200jslang._date._months._'+i), i); } } //向前一月 calendar.prototype.goprevmonth=function(e){ if(this.year==this.beginyear && this.month==0){return;} this.month--; if(this.month==-1){ this.year--; this.month=11; } this.date=new date(this.year, this.month, 1); this.changeselect(); this.binddata(); } //向后一月 calendar.prototype.gonextmonth=function(e){ if(this.year==this.endyear && this.month==11){return;} this.month++; if(this.month==12){ this.year++; this.month=0; } this.date=new date(this.year, this.month, 1); this.changeselect(); this.binddata(); } //改变select选中状态 calendar.prototype.changeselect=function(){ var cy=this.calendaryear; var cm=this.calendarmonth; for(var i= 0; i datearray.length-1) break; tds[i].innerhtml=datearray[i]; if(datearray[i]!=' '){ tds[i].onclick=function(){ if(calendar.datecontrol!=null){ calendar.datecontrol.value=new date(calendar.date.getfullyear(), calendar.date.getmonth(), this.innerhtml).format(calendar.dateformatstyle); } calendar.hide(); } tds[i].onmouseover=function(){ this.style.backgroundcolor=calendar.colors['td_bg_over']; } tds[i].onmouseout=function(){ this.style.backgroundcolor=calendar.colors['td_bg_out']; } if(new date().format(calendar.dateformatstyle)== new date(calendar.date.getfullyear(), calendar.date.getmonth(), datearray[i]).format(calendar.dateformatstyle)) { tds[i].style.backgroundcolor=calendar.colors['cur_bg']; tds[i].onmouseover=function(){ this.style.backgroundcolor=calendar.colors['td_bg_over']; } tds[i].onmouseout=function(){ this.style.backgroundcolor=calendar.colors['cur_bg']; } }//end if //设置已被选择的日期单元格背影色 if(calendar.datecontrol!=null && calendar.datecontrol.value==new date(calendar.date.getfullyear(), calendar.date.getmonth(), datearray[i]).format(calendar.dateformatstyle)) { tds[i].style.backgroundcolor=calendar.colors['sel_bg']; tds[i].onmouseover=function(){ this.style.backgroundcolor=calendar.colors['td_bg_over']; } tds[i].onmouseout=function(){ this.style.backgroundcolor=calendar.colors['sel_bg']; } } } } } //根据年、月得到月视图数据(数组形式) calendar.prototype.getmonthviewarray=function (y, m) { var mvarray=[]; var dayoffirstday=new date(y, m, 1).getday(); var daysofmonth=new date(y, m+1, 0).getdate(); for(var i=0; i<42; i++) { mvarray[i]=' '; } for(var i=0; i 0)?new date(dateobj.value.todate(this.dateformatstyle)):new date() ;//若为空则显示当前月份 this.year=this.date.getfullyear(); this.month=this.date.getmonth(); this.changeselect(); this.binddata(); if(popcontrol==null){ popcontrol=dateobj; } var xy=this.getabspoint(popcontrol); this.panel.style.left=xy.x-25+'px'; this.panel.style.top=(xy.y+dateobj.offsetheight)+'px'; this.panel.style.display=''; this.container.style.display=''; dateobj.onblur=function(){calendar.onblur();} this.container.onmouseover=function(){isfocus=true;} this.container.onmouseout=function(){isfocus=false;} } //隐藏日历 calendar.prototype.hide=function() { this.panel.style.display='none'; this.container.style.display='none'; isfocus=false; } //焦点转移时隐藏日历 calendar.prototype.onblur=function() { if(!isfocus){this.hide();} } document.write('');