漂亮的 js 日历(把日期输入到文本框)

None.gif <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
None.gif
< HTML >
None.gif
< HEAD >
None.gif
< TITLE >  New Document  </ TITLE >
None.gif
</ HEAD >
None.gif
None.gif
< BODY >
ExpandedBlockStart.gifContractedBlock.gif
< script  language ="javascript" > dot.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif 
function openScript(url, width, height)dot.gif{
ExpandedBlockEnd.gif 
var Win = window.open(url,"openScript",'width=+ width + ',height=+ height + ',resizable=1,scrollbars=yes,menubar=no,status=yes' );}

None.gif
</ script >
None.gif
ExpandedBlockStart.gifContractedBlock.gif
< SCRIPT  language ="javascript" > dot.gif
InBlock.gif
var bMoveable=false;  //设置日历是否可以拖动
InBlock.gif
var _VersionInfo="Version:2.0"
InBlock.gif
//2.0作者:walkingpoison
InBlock.gif//
1.0作者: F.R.Huang(meizz)
InBlock.gif//
MAIL: meizz@hzcnc.com
InBlock.gif

InBlock.gif
InBlock.gif
var strFrame;  //存放日历层的HTML代码
InBlock.gif
document.writeln('<iframe id=meizzDateLayer Author=wayx frameborder=0 style="position: absolute; width: 144; height: 211; z-index: 9998; display: none"></iframe>');
InBlock.gifstrFrame
='<style>';
ExpandedSubBlockStart.gifContractedSubBlock.gifstrFrame
+='INPUT.buttondot.gif{BORDER-RIGHT: #ff9900 1px solid;BORDER-TOP: #ff9900 1px solid;BORDER-LEFT: #ff9900 1px solid;';
ExpandedSubBlockEnd.gifstrFrame
+='BORDER-BOTTOM: #ff9900 1px solid;BACKGROUND-COLOR: #fff8ec;font-family:宋体;}
';
ExpandedSubBlockStart.gifContractedSubBlock.gifstrFrame
+='TDdot.gif{FONT-SIZE: 9pt;font-family:宋体;}';
InBlock.gifstrFrame
+='</style>';
InBlock.gifstrFrame
+='<scr' + 'ipt>';
ExpandedSubBlockStart.gifContractedSubBlock.gifstrFrame
+='var datelayerx,datelayery; /**//*存放日历控件的鼠标位置*/';
ExpandedSubBlockStart.gifContractedSubBlock.gifstrFrame
+='var bDrag; /**//*标记是否开始拖动*/';
ExpandedSubBlockStart.gifContractedSubBlock.gifstrFrame
+='function document.onmousemove() /**//*在鼠标移动事件中,如果开始拖动日历,则移动日历*/';
ExpandedSubBlockStart.gifContractedSubBlock.gifstrFrame
+='dot.gif{if(bDrag && window.event.button==1)';
ExpandedSubBlockStart.gifContractedSubBlock.gifstrFrame
+=dot.gif{var DateLayer=parent.document.all.meizzDateLayer.style;';
ExpandedSubBlockStart.gifContractedSubBlock.gifstrFrame
+='  DateLayer.posLeft += window.event.clientX-datelayerx;/**//*由于每次移动以后鼠标位置都恢复为初始的位置,因此写法与div中不同*/';
ExpandedSubBlockEnd.gifstrFrame
+='  DateLayer.posTop += window.event.clientY-datelayery;}
}
';
ExpandedSubBlockStart.gifContractedSubBlock.gifstrFrame
+='function DragStart()  /**//*开始日历拖动*/';
ExpandedSubBlockStart.gifContractedSubBlock.gifstrFrame
+='dot.gif{var DateLayer=parent.document.all.meizzDateLayer.style;';
InBlock.gifstrFrame
+=' datelayerx=window.event.clientX;';
InBlock.gifstrFrame
+=' datelayery=window.event.clientY;';
ExpandedSubBlockEnd.gifstrFrame
+=' bDrag=true;}
';
ExpandedSubBlockStart.gifContractedSubBlock.gifstrFrame
+='function DragEnd()dot.gif{  /**//*结束日历拖动*/';
ExpandedSubBlockEnd.gifstrFrame
+=' bDrag=false;}
';
InBlock.gifstrFrame
+='</scr' + 'ipt>';
InBlock.gifstrFrame
+='<div style="z-index:9999;position: absolute; left:0; top:0;" onselectstart="return false"><span id=tmpSelectYearLayer Author=wayx style="z-index: 9999;position: absolute;top: 3; left: 19;display: none"></span>';
InBlock.gifstrFrame
+='<span id=tmpSelectMonthLayer Author=wayx style="z-index: 9999;position: absolute;top: 3; left: 78;display: none"></span>';
InBlock.gifstrFrame
+='<table border=1 cellspacing=0 cellpadding=0 width=142 height=160 bordercolor=#ff9900 bgcolor=#ff9900 Author="wayx">';
InBlock.gifstrFrame
+='  <tr Author="wayx"><td width=142 height=23 Author="wayx" bgcolor=#FFFFFF><table border=0 cellspacing=1 cellpadding=0 width=140 Author="wayx" height=23>';
InBlock.gifstrFrame
+='      <tr align=center Author="wayx"><td width=16 align=center bgcolor=#ff9900 style="font-size:12px;cursor: hand;color: #ffffff" ';
InBlock.gifstrFrame
+='        onclick="parent.meizzPrevM()" title="向前翻 1 月" Author=meizz><b Author=meizz><</b>';
InBlock.gifstrFrame
+='        </td><td width=60 align=center style="font-size:12px;cursor:default" Author=meizz ';
InBlock.gifstrFrame
+='onmouseover="style.backgroundColor=\'#FFD700\'" onmouseout="style.backgroundColor=\'white\'" ';
InBlock.gifstrFrame
+='onclick="parent.tmpSelectYearInnerHTML(this.innerText.substring(0,4))" title="点击这里选择年份"><span Author=meizz id=meizzYearHead></span></td>';
InBlock.gifstrFrame
+='<td width=48 align=center style="font-size:12px;cursor:default" Author=meizz onmouseover="style.backgroundColor=\'#FFD700\'" ';
InBlock.gifstrFrame
+=' onmouseout="style.backgroundColor=\'white\'" onclick="parent.tmpSelectMonthInnerHTML(this.innerText.length==3?this.innerText.substring(0,1):this.innerText.substring(0,2))"';
InBlock.gifstrFrame
+='        title="点击这里选择月份"><span id=meizzMonthHead Author=meizz></span></td>';
InBlock.gifstrFrame
+='        <td width=16 bgcolor=#ff9900 align=center style="font-size:12px;cursor: hand;color: #ffffff" ';
InBlock.gifstrFrame
+='         onclick="parent.meizzNextM()" title="向后翻 1 月" Author=meizz><b Author=meizz>></b></td></tr>';
InBlock.gifstrFrame
+='    </table></td></tr>';
InBlock.gifstrFrame
+='  <tr Author="wayx"><td width=142 height=18 Author="wayx">';
InBlock.gifstrFrame
+='<table border=1 cellspacing=0 cellpadding=0 bgcolor=#ff9900 ' + (bMoveable? 'onmousedown="DragStart()" onmouseup="DragEnd()"':'');
InBlock.gifstrFrame
+=' BORDERCOLORLIGHT=#FF9900 BORDERCOLORDARK=#FFFFFF width=140 height=20 Author="wayx" style="cursor:' + (bMoveable ? 'move':'default') + '">';
InBlock.gifstrFrame
+='<tr Author="wayx" align=center valign=bottom><td style="font-size:12px;color:#FFFFFF" Author=meizz></td>';
InBlock.gifstrFrame
+='<td style="font-size:12px;color:#FFFFFF" Author=meizz></td><td style="font-size:12px;color:#FFFFFF" Author=meizz></td>';
InBlock.gifstrFrame
+='<td style="font-size:12px;color:#FFFFFF" Author=meizz></td><td style="font-size:12px;color:#FFFFFF" Author=meizz></td>';
InBlock.gifstrFrame
+='<td style="font-size:12px;color:#FFFFFF" Author=meizz></td><td style="font-size:12px;color:#FFFFFF" Author=meizz></td></tr>';
InBlock.gifstrFrame
+='</table></td></tr><!-- Author:F.R.Huang(meizz) http://www.meizz.com/ mail: meizz@hzcnc.com 2002-10-8 -->';
InBlock.gif
strFrame+='  <tr Author="wayx"><td width=142 height=120 Author="wayx">';
InBlock.gifstrFrame
+='    <table border=1 cellspacing=2 cellpadding=0 BORDERCOLORLIGHT=#FF9900 BORDERCOLORDARK=#FFFFFF bgcolor=#fff8ec width=140 height=120 Author="wayx">';
ExpandedSubBlockStart.gifContractedSubBlock.gif
var n=0for (j=0;j<5;j++)dot.gif{ strFrame+= ' <tr align=center Author="wayx">'; for (i=0;i<7;i++)dot.gif{
ExpandedSubBlockEnd.gifstrFrame
+='<td width=20 height=20 id=meizzDay'+n+' style="font-size:12px" Author=meizz onclick=parent.meizzDayClick(this.innerText,0)></td>';n++;}

ExpandedSubBlockEnd.gifstrFrame
+='</tr>';}

InBlock.gifstrFrame
+='      <tr align=center Author="wayx">';
InBlock.gif
for (i=35;i<39;i++)strFrame+='<td width=20 height=20 id=meizzDay'+i+' style="font-size:12px" Author=wayx onclick="parent.meizzDayClick(this.innerText,0)"></td>';
InBlock.gifstrFrame
+='        <td colspan=3 align=right ><span onclick=parent.closeLayer() style="font-size:12px;cursor: hand"';
InBlock.gifstrFrame
+='         ><u>关闭</u></span> </td></tr>';
InBlock.gifstrFrame
+='    </table></td></tr><tr Author="wayx"><td Author="wayx">';
InBlock.gifstrFrame
+='        <table border=0 cellspacing=1 cellpadding=0 width=100% Author="wayx" bgcolor=#FFFFFF>';
InBlock.gifstrFrame
+='          <tr Author="wayx"><td Author=meizz align=left><input Author=meizz type=button class=button value="<<" title="向前翻 1 年" onclick="parent.meizzPrevY()" ';
InBlock.gifstrFrame
+='             onfocus="this.blur()" style="font-size: 12px; height: 20px"><input Author=meizz class=button title="向前翻 1 月" type=button ';
InBlock.gifstrFrame
+='             value="" onclick="parent.meizzPrevM()" onfocus="this.blur()" style="font-size: 12px; height: 20px"></td><td ';
InBlock.gifstrFrame
+='             Author=meizz align=center><input Author=meizz type=button class=button value=今天 onclick="parent.meizzToday()" ';
InBlock.gifstrFrame
+='             onfocus="this.blur()" title="当前日期" style="font-size: 12px; height: 20px; cursor:hand"></td><td ';
InBlock.gifstrFrame
+='             Author=meizz align=right><input Author=meizz type=button class=button value=" >" onclick="parent.meizzNextM()" ';
InBlock.gifstrFrame
+='             onfocus="this.blur()" title="向后翻 1 月" class=button style="font-size: 12px; height: 20px"><input ';
InBlock.gifstrFrame
+='             Author=meizz type=button class=button value=">>" title="向后翻 1 年" onclick="parent.meizzNextY()"';
InBlock.gifstrFrame
+='             onfocus="this.blur()" style="font-size: 12px; height: 20px"></td>';
InBlock.gifstrFrame
+='</tr></table></td></tr></table></div>';
InBlock.gif
InBlock.gifwindow.frames.meizzDateLayer.document.writeln(strFrame);
InBlock.gifwindow.frames.meizzDateLayer.document.close();  
//解决ie进度条不结束的问题
InBlock.gif

InBlock.gif
//==================================================== WEB 页面显示部分 ======================================================
InBlock.gif
var outObject;
InBlock.gif
var outButton;  //点击的按钮
InBlock.gif
var outDate="";  //存放对象的日期
InBlock.gif
var odatelayer=window.frames.meizzDateLayer.document.all;  //存放日历对象
InBlock.gif
function setday(tt,obj) //主调函数
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif 
if (arguments.length >  2)dot.gif{alert("对不起!传入本控件的参数太多!");return;}
ExpandedSubBlockStart.gifContractedSubBlock.gif 
if (arguments.length == 0)dot.gif{alert("对不起!您没有传回本控件任何参数!");return;}
InBlock.gif 
var dads  = document.all.meizzDateLayer.style;
InBlock.gif 
var th = tt;
InBlock.gif 
var ttop  = tt.offsetTop;     //TT控件的定位点高
InBlock.gif
 var thei  = tt.clientHeight;  //TT控件本身的高
InBlock.gif
 var tleft = tt.offsetLeft;    //TT控件的定位点宽
InBlock.gif
 var ttyp  = tt.type;          //TT控件的类型
ExpandedSubBlockStart.gifContractedSubBlock.gif
 while (tt = tt.offsetParent)dot.gif{ttop+=tt.offsetTop; tleft+=tt.offsetLeft;}
InBlock.gif dads.top  
= (ttyp=="image")? ttop+thei : ttop+thei+6;
InBlock.gif dads.left 
= tleft;
InBlock.gif outObject 
= (arguments.length == 1? th : obj;
InBlock.gif outButton 
= (arguments.length == 1? null : th; //设定外部点击的按钮
InBlock.gif
 //根据当前输入框的日期显示日历的年月
ExpandedSubBlockStart.gifContractedSubBlock.gif
 var reg = /^(\d+)-(\ddot.gif{1,2})-(\ddot.gif{1,2})$/
InBlock.gif 
var r = outObject.value.match(reg); 
ExpandedSubBlockStart.gifContractedSubBlock.gif 
if(r!=null)dot.gif{
InBlock.gif  r[
2]=r[2]-1
InBlock.gif  
var d= new Date(r[1], r[2],r[3]); 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
if(d.getFullYear()==r[1&& d.getMonth()==r[2&& d.getDate()==r[3])dot.gif{
InBlock.gif   outDate
=d;  //保存外部传入的日期
ExpandedSubBlockEnd.gif
  }

InBlock.gif  
else outDate="";
InBlock.gif   meizzSetDay(r[
1],r[2]+1);
ExpandedSubBlockEnd.gif }

ExpandedSubBlockStart.gifContractedSubBlock.gif 
elsedot.gif{
InBlock.gif  outDate
="";
InBlock.gif  meizzSetDay(
new Date().getFullYear(), new Date().getMonth() + 1);
ExpandedSubBlockEnd.gif }

InBlock.gif dads.display 
= '';
InBlock.gif
InBlock.gif event.returnValue
=false;
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
var MonHead = new Array(12);         //定义阳历中每个月的最大天数
InBlock.gif
    MonHead[0= 31; MonHead[1= 28; MonHead[2= 31; MonHead[3= 30; MonHead[4]  = 31; MonHead[5]  = 30;
InBlock.gif    MonHead[
6= 31; MonHead[7= 31; MonHead[8= 30; MonHead[9= 31; MonHead[10= 30; MonHead[11= 31;
InBlock.gif
InBlock.gif
var meizzTheYear=new Date().getFullYear(); //定义年的变量的初始值
InBlock.gif
var meizzTheMonth=new Date().getMonth()+1//定义月的变量的初始值
InBlock.gif
var meizzWDay=new Array(39);               //定义写日期的数组
InBlock.gif

InBlock.gif
function document.onclick() //任意点击时关闭该控件 //ie6的情况可以由下面的切换焦点处理代替
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif  
with(window.event)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gifif (srcElement.getAttribute("Author")==null && srcElement != outObject && srcElement != outButton)
InBlock.gif    closeLayer();
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
function document.onkeyup()  //按Esc键关闭,切换焦点关闭
ExpandedSubBlockStart.gifContractedSubBlock.gif
  dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if (window.event.keyCode==27)dot.gif{
InBlock.gif  
if(outObject)outObject.blur();
InBlock.gif  closeLayer();
ExpandedSubBlockEnd.gif }

InBlock.gif 
else if(document.activeElement)
InBlock.gif  
if(document.activeElement.getAttribute("Author")==null && document.activeElement != outObject && document.activeElement != outButton)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   closeLayer();
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif
function meizzWriteHead(yy,mm)  //往 head 中写入当前的年与月
ExpandedSubBlockStart.gifContractedSubBlock.gif
  dot.gif{
InBlock.gif odatelayer.meizzYearHead.innerText  
= yy + " 年";
InBlock.gif    odatelayer.meizzMonthHead.innerText 
= mm + " 月";
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif
function tmpSelectYearInnerHTML(strYear) //年份的下拉框
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (strYear.match(/\D/)!=null)dot.gif{alert("年份输入参数不是数字!");return;}
InBlock.gif  
//var m = (strYear) ? strYear : new Date().getFullYear();
InBlock.gif
  var m = new Date().getFullYear();
ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (m < 1000 || m > 9999dot.gif{alert("年份值不在 1000 到 9999 之间!");return;}
InBlock.gif  
var n = m - 100;
InBlock.gif  
if (n < 1000) n = 1000;
InBlock.gif  
if (n + 120 > 9999) n = 9974;
InBlock.gif  
var s = "<select Author=meizz name=tmpSelectYear style='font-size: 12px' "
InBlock.gif     s 
+= "οnblur='document.all.tmpSelectYearLayer.style.display=\"none\""
InBlock.gif     s 
+= "οnchange='document.all.tmpSelectYearLayer.style.display=\"none\";"
InBlock.gif     s 
+= "parent.meizzTheYear = this.value; parent.meizzSetDay(parent.meizzTheYear,parent.meizzTheMonth)'>\r\n";
InBlock.gif  
var selectInnerHTML = s;
InBlock.gif  
for (var i = n; i < n + 120; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif    
if (i == m)
ExpandedSubBlockStart.gifContractedSubBlock.gif       
dot.gif{selectInnerHTML += "<option Author=wayx value='" + i + "' selected>" + i + "" + "</option>\r\n";}
ExpandedSubBlockStart.gifContractedSubBlock.gif    
else dot.gif{selectInnerHTML += "<option Author=wayx value='" + i + "'>" + i + "" + "</option>\r\n";}
ExpandedSubBlockEnd.gif  }

InBlock.gif  selectInnerHTML 
+= "</select>";
InBlock.gif  odatelayer.tmpSelectYearLayer.style.display
="";
InBlock.gif  odatelayer.tmpSelectYearLayer.innerHTML 
= selectInnerHTML;
InBlock.gif  odatelayer.tmpSelectYear.focus();
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
function tmpSelectMonthInnerHTML(strMonth) //月份的下拉框
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (strMonth.match(/\D/)!=null)dot.gif{alert("月份输入参数不是数字!");return;}
InBlock.gif  
var m = (strMonth) ? strMonth : new Date().getMonth() + 1;
InBlock.gif  
var s = "<select Author=meizz name=tmpSelectMonth style='font-size: 12px' "
InBlock.gif     s 
+= "οnblur='document.all.tmpSelectMonthLayer.style.display=\"none\""
InBlock.gif     s 
+= "οnchange='document.all.tmpSelectMonthLayer.style.display=\"none\";"
InBlock.gif     s 
+= "parent.meizzTheMonth = this.value; parent.meizzSetDay(parent.meizzTheYear,parent.meizzTheMonth)'>\r\n";
InBlock.gif  
var selectInnerHTML = s;
InBlock.gif  
for (var i = 1; i < 13; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif    
if (i == m)
ExpandedSubBlockStart.gifContractedSubBlock.gif       
dot.gif{selectInnerHTML += "<option Author=wayx value='"+i+"' selected>"+i+""+"</option>\r\n";}
ExpandedSubBlockStart.gifContractedSubBlock.gif    
else dot.gif{selectInnerHTML += "<option Author=wayx value='"+i+"'>"+i+""+"</option>\r\n";}
ExpandedSubBlockEnd.gif  }

InBlock.gif  selectInnerHTML 
+= "</select>";
InBlock.gif  odatelayer.tmpSelectMonthLayer.style.display
="";
InBlock.gif  odatelayer.tmpSelectMonthLayer.innerHTML 
= selectInnerHTML;
InBlock.gif  odatelayer.tmpSelectMonth.focus();
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
function closeLayer()               //这个层的关闭
ExpandedSubBlockStart.gifContractedSubBlock.gif
  dot.gif{
InBlock.gif    document.all.meizzDateLayer.style.display
="none";
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif
function IsPinYear(year)            //判断是否闰平年
ExpandedSubBlockStart.gifContractedSubBlock.gif
  dot.gif{
InBlock.gif    
if (0==year%4&&((year%100!=0)||(year%400==0))) return true;else return false;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif
function GetMonthCount(year,month)  //闰年二月为29天
ExpandedSubBlockStart.gifContractedSubBlock.gif
  dot.gif{
InBlock.gif    
var c=MonHead[month-1];if((month==2)&&IsPinYear(year)) c++;return c;
ExpandedSubBlockEnd.gif  }

InBlock.gif
function GetDOW(day,month,year)     //求某天的星期几
ExpandedSubBlockStart.gifContractedSubBlock.gif
  dot.gif{
InBlock.gif    
var dt=new Date(year,month-1,day).getDay()/7return dt;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif
function meizzPrevY()  //往前翻 Year
ExpandedSubBlockStart.gifContractedSubBlock.gif
  dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if(meizzTheYear > 999 && meizzTheYear <10000)dot.gif{meizzTheYear--;}
ExpandedSubBlockStart.gifContractedSubBlock.gif    
elsedot.gif{alert("年份超出范围(1000-9999)!");}
InBlock.gif    meizzSetDay(meizzTheYear,meizzTheMonth);
ExpandedSubBlockEnd.gif  }

InBlock.gif
function meizzNextY()  //往后翻 Year
ExpandedSubBlockStart.gifContractedSubBlock.gif
  dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if(meizzTheYear > 999 && meizzTheYear <10000)dot.gif{meizzTheYear++;}
ExpandedSubBlockStart.gifContractedSubBlock.gif    
elsedot.gif{alert("年份超出范围(1000-9999)!");}
InBlock.gif    meizzSetDay(meizzTheYear,meizzTheMonth);
ExpandedSubBlockEnd.gif  }

InBlock.gif
function meizzToday()  //Today Button
ExpandedSubBlockStart.gifContractedSubBlock.gif
  dot.gif{
InBlock.gif 
var today;
InBlock.gif    meizzTheYear 
= new Date().getFullYear();
InBlock.gif    meizzTheMonth 
= new Date().getMonth()+1;
InBlock.gif    today
=new Date().getDate();
InBlock.gif    
//meizzSetDay(meizzTheYear,meizzTheMonth);
ExpandedSubBlockStart.gifContractedSubBlock.gif
    if(outObject)dot.gif{
InBlock.gif  outObject.value
=meizzTheYear + "-" + meizzTheMonth + "-" + today;
ExpandedSubBlockEnd.gif    }

InBlock.gif    closeLayer();
ExpandedSubBlockEnd.gif  }

InBlock.gif
function meizzPrevM()  //往前翻月份
ExpandedSubBlockStart.gifContractedSubBlock.gif
  dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if(meizzTheMonth>1)dot.gif{meizzTheMonth--}elsedot.gif{meizzTheYear--;meizzTheMonth=12;}
InBlock.gif    meizzSetDay(meizzTheYear,meizzTheMonth);
ExpandedSubBlockEnd.gif  }

InBlock.gif
function meizzNextM()  //往后翻月份
ExpandedSubBlockStart.gifContractedSubBlock.gif
  dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if(meizzTheMonth==12)dot.gif{meizzTheYear++;meizzTheMonth=1}elsedot.gif{meizzTheMonth++}
InBlock.gif    meizzSetDay(meizzTheYear,meizzTheMonth);
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif
function meizzSetDay(yy,mm)   //主要的写程序**********
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif  meizzWriteHead(yy,mm);
InBlock.gif  
//设置当前年月的公共变量为传入值
InBlock.gif
  meizzTheYear=yy;
InBlock.gif  meizzTheMonth
=mm;
InBlock.gif  
ExpandedSubBlockStart.gifContractedSubBlock.gif  
for (var i = 0; i < 39; i++)dot.gif{meizzWDay[i]=""};  //将显示框的内容全部清空
InBlock.gif
  var day1 = 1,day2=1,firstday = new Date(yy,mm-1,1).getDay();  //某月第一天的星期几
InBlock.gif
  for (i=0;i<firstday;i++)meizzWDay[i]=GetMonthCount(mm==1?yy-1:yy,mm==1?12:mm-1)-firstday+i+1 //上个月的最后几天
ExpandedSubBlockStart.gifContractedSubBlock.gif
  for (i = firstday; day1 < GetMonthCount(yy,mm)+1; i++)dot.gif{meizzWDay[i]=day1;day1++;}
ExpandedSubBlockStart.gifContractedSubBlock.gif  
for (i=firstday+GetMonthCount(yy,mm);i<39;i++)dot.gif{meizzWDay[i]=day2;day2++}
InBlock.gif  
for (i = 0; i < 39; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gifvar da = eval("odatelayer.meizzDay"+i)     //书写新的一个月的日期星期排列
InBlock.gif
    if (meizzWDay[i]!="")
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif
InBlock.gif  
//初始化边框
InBlock.gif
  da.borderColorLight="#FF9900";
InBlock.gif  da.borderColorDark
="#FFFFFF";
InBlock.gif  
if(i<firstday)  //上个月的部分
ExpandedSubBlockStart.gifContractedSubBlock.gif
  dot.gif{
InBlock.gif   da.innerHTML
="<b><font color=gray>" + meizzWDay[i] + "</font></b>";
InBlock.gif   da.title
=(mm==1?12:mm-1+"" + meizzWDay[i] + "";
InBlock.gif   da.onclick
=Function("meizzDayClick(this.innerText,-1)");
InBlock.gif   
if(!outDate)
InBlock.gif    da.style.backgroundColor 
= ((mm==1?yy-1:yy) == new Date().getFullYear() && 
InBlock.gif     (mm
==1?12:mm-1== new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate()) ?
InBlock.gif             
"#FFD700":"#e0e0e0";
InBlock.gif   
else
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    da.style.backgroundColor 
=((mm==1?yy-1:yy)==outDate.getFullYear() && (mm==1?12:mm-1)== outDate.getMonth() + 1 && 
InBlock.gif    meizzWDay[i]
==outDate.getDate())? "#00ffff" :
InBlock.gif    (((mm
==1?yy-1:yy) == new Date().getFullYear() && (mm==1?12:mm-1== new Date().getMonth()+1 && 
InBlock.gif    meizzWDay[i] 
== new Date().getDate()) ? "#FFD700":"#e0e0e0");
InBlock.gif    
//将选中的日期显示为凹下去
InBlock.gif
    if((mm==1?yy-1:yy)==outDate.getFullYear() && (mm==1?12:mm-1)== outDate.getMonth() + 1 && 
InBlock.gif    meizzWDay[i]
==outDate.getDate())
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     da.borderColorLight
="#FFFFFF";
InBlock.gif     da.borderColorDark
="#FF9900";
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

InBlock.gif  
else if (i>=firstday+GetMonthCount(yy,mm))  //下个月的部分
ExpandedSubBlockStart.gifContractedSubBlock.gif
  dot.gif{
InBlock.gif   da.innerHTML
="<b><font color=gray>" + meizzWDay[i] + "</font></b>";
InBlock.gif   da.title
=(mm==12?1:mm+1+"" + meizzWDay[i] + "";
InBlock.gif   da.onclick
=Function("meizzDayClick(this.innerText,1)");
InBlock.gif   
if(!outDate)
InBlock.gif    da.style.backgroundColor 
= ((mm==12?yy+1:yy) == new Date().getFullYear() && 
InBlock.gif     (mm
==12?1:mm+1== new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate()) ?
InBlock.gif             
"#FFD700":"#e0e0e0";
InBlock.gif   
else
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    da.style.backgroundColor 
=((mm==12?yy+1:yy)==outDate.getFullYear() && (mm==12?1:mm+1)== outDate.getMonth() + 1 && 
InBlock.gif    meizzWDay[i]
==outDate.getDate())? "#00ffff" :
InBlock.gif    (((mm
==12?yy+1:yy) == new Date().getFullYear() && (mm==12?1:mm+1== new Date().getMonth()+1 && 
InBlock.gif    meizzWDay[i] 
== new Date().getDate()) ? "#FFD700":"#e0e0e0");
InBlock.gif    
//将选中的日期显示为凹下去
InBlock.gif
    if((mm==12?yy+1:yy)==outDate.getFullYear() && (mm==12?1:mm+1)== outDate.getMonth() + 1 && 
InBlock.gif    meizzWDay[i]
==outDate.getDate())
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     da.borderColorLight
="#FFFFFF";
InBlock.gif     da.borderColorDark
="#FF9900";
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

InBlock.gif  
else  //本月的部分
ExpandedSubBlockStart.gifContractedSubBlock.gif
  dot.gif{
InBlock.gif   da.innerHTML
="<b>" + meizzWDay[i] + "</b>";
InBlock.gif   da.title
=mm +"" + meizzWDay[i] + "";
InBlock.gif   da.onclick
=Function("meizzDayClick(this.innerText,0)");  //给td赋予onclick事件的处理
InBlock.gif
   //如果是当前选择的日期,则显示亮蓝色的背景;如果是当前日期,则显示暗黄色背景
InBlock.gif
   if(!outDate)
InBlock.gif    da.style.backgroundColor 
= (yy == new Date().getFullYear() && mm == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate())?
InBlock.gif     
"#FFD700":"#e0e0e0";
InBlock.gif   
else
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    da.style.backgroundColor 
=(yy==outDate.getFullYear() && mm== outDate.getMonth() + 1 && meizzWDay[i]==outDate.getDate())?
InBlock.gif     
"#00ffff":((yy == new Date().getFullYear() && mm == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate())?
InBlock.gif     
"#FFD700":"#e0e0e0");
InBlock.gif    
//将选中的日期显示为凹下去
InBlock.gif
    if(yy==outDate.getFullYear() && mm== outDate.getMonth() + 1 && meizzWDay[i]==outDate.getDate())
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     da.borderColorLight
="#FFFFFF";
InBlock.gif     da.borderColorDark
="#FF9900";
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

InBlock.gif        da.style.cursor
="hand"
ExpandedSubBlockEnd.gif      }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
elsedot.gif{da.innerHTML="";da.style.backgroundColor="";da.style.cursor="default"}
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
function meizzDayClick(n,ex)  //点击显示框选取日期,主输入函数*************
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif  
var yy=meizzTheYear;
InBlock.gif  
var mm = parseInt(meizzTheMonth)+ex; //ex表示偏移量,用于选择上个月份和下个月份的日期
InBlock.gif
 //判断月份,并进行对应的处理
ExpandedSubBlockStart.gifContractedSubBlock.gif
 if(mm<1)dot.gif{
InBlock.gif  yy
--;
InBlock.gif  mm
=12+mm;
ExpandedSubBlockEnd.gif }

ExpandedSubBlockStart.gifContractedSubBlock.gif 
else if(mm>12)dot.gif{
InBlock.gif  yy
++;
InBlock.gif  mm
=mm-12;
ExpandedSubBlockEnd.gif }

InBlock.gif 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
if (mm < 10)dot.gif{mm = "0" + mm;}
InBlock.gif  
if (outObject)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if (!n) dot.gif{//outObject.value=""; 
ExpandedSubBlockEnd.gif
      return;}

ExpandedSubBlockStart.gifContractedSubBlock.gif    
if ( n < 10)dot.gif{n = "0" + n;}
InBlock.gif    outObject.value
= yy + "-" + mm + "-" + n ; //注:在这里你可以输出改成你想要的格式
InBlock.gif
    closeLayer(); 
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockStart.gifContractedSubBlock.gif  
else dot.gif{closeLayer(); alert("您所要输出的控件对象并不存在!");}
ExpandedBlockEnd.gif}

None.gif
</ SCRIPT >
None.gif
< input  type =textbox   onfocus ="setday(this)" >
None.gif
</ BODY >
None.gif
</ HTML >

转载于:https://www.cnblogs.com/airfey/archive/2007/02/06/642608.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值