document.writeln('<div id=ggDateLayer style="position: absolute; width: 142; height: 166; z-index: 9998; display: none">');
document.writeln('<span id=tmpSelectYearLayer style="z-index: 9999;position: absolute;top: 2; left: 18;display: none"></span>');
document.writeln('<span id=tmpSelectMonthLayer style="z-index: 9999;position: absolute;top: 2; left: 75;display: none"></span>');
document.writeln('<table width="100%" border=0 cellspacing=1 cellpadding=0 width=142 height=160 bgcolor=#808080 onselectstart="return false">');
document.writeln(' <tr><td width=142 height=23 bgcolor=#FFFFFF><table width="100%" border=0 cellspacing=1 cellpadding=0 width=140 height=23>');
document.writeln(' <tr align=center><td width=15 align=center bgcolor=#808080 style="font-size:12px;cursor: hand;color: #FFD700" ');
document.writeln(' onclick="ggPrevM()" title="上月" whatever=good><b whatever=good><</b>');
document.writeln(' </td><td width=15 align=center bgcolor=#808080 style="font-size:11px;cursor: hand;color: #FFD700" ');
document.writeln(' onclick="ggPrevY()" title="上年" whatever=good><b whatever=good><<</b>');
document.writeln(' </td><td width=60 align=center style="font-size:11px;cursor:default" whatever=good>');
document.writeln(' <span whatever=good id=ggYearHead ></span> 年 <span');
document.writeln(' id=ggMonthHead whatever=good ></span> 月</td>');
document.writeln(' <td width=15 bgcolor=#808080 align=center style="font-size:11px;cursor: hand;color: #FFD700" ');
document.writeln(' onclick="ggNextY()" title="下年" whatever=good><b whatever=good>>></b></td>');
document.writeln(' <td width=15 bgcolor=#808080 align=center style="font-size:11px;cursor: hand;color: #FFD700" ');
document.writeln(' onclick="ggNextM()" title="下月" whatever=good><b whatever=good>></b></td></tr>');
document.writeln(' </table></td></tr>');
document.writeln(' <tr><td width=142 height=120>');
document.writeln(' <table width="100%" border=0 cellspacing=1 cellpadding=0 width=140 height=120 bgcolor=#FFFFFF>');
var n=0; for (j=0;j<5;j++){ document.writeln (' <tr align=center>'); for (i=0;i<7;i++){
document.writeln('<td width=20 height=20 id=ggDay'+n+' style="font-size:12px" whatever=good onclick=ggDayClick(this.innerText)></td>');n++;}
document.writeln('</tr>');}
document.writeln(' <tr align=center><td width=20 height=20 style="font-size:12px" id=ggDay35 whatever=good ');
document.writeln(' onclick=ggDayClick(this.innerText)></td>');
document.writeln(' <td width=20 height=20 style="font-size:12px" id=ggDay36 whatever=good onclick=ggDayClick(this.innerText)></td></tr>');
document.writeln(' </table></td></tr><tr><td>');
document.writeln(' <table width="100%" border=0 cellspacing=1 cellpadding=0 width=100% bgcolor=#FFFFFF>');
document.writeln('</tr></table></td></tr></table></div>');
//==================================================== WEB 页面显示部分 ======================================================
var outObject;
function setday(tt,obj) //主调函数
{
var dads = document.all.ggDateLayer.style;var th = tt;
var ttop = tt.offsetTop; //TT控件的定位点高
var thei = tt.clientHeight; //TT控件本身的高
var tleft = tt.offsetLeft; //TT控件的定位点宽
var ttyp = tt.type; //TT控件的类型
while (tt = tt.offsetParent){ttop+=tt.offsetTop; tleft+=tt.offsetLeft;}
dads.top = (ttyp=="image")? ttop+thei : ttop+thei+6;
dads.left = tleft;
outObject = (arguments.length == 1) ? th : obj;
dads.display = '';
event.returnValue=false;
}
var MonHead = new Array(12); //定义阳历中每个月的最大天数
MonHead[0] = 31; MonHead[1] = 28; MonHead[2] = 31; MonHead[3] = 30; MonHead[4] = 31; MonHead[5] = 30;
MonHead[6] = 31; MonHead[7] = 31; MonHead[8] = 30; MonHead[9] = 31; MonHead[10] = 30; MonHead[11] = 31;
var ggTheYear=new Date().getFullYear(); //定义年的变量的初始值
var ggTheMonth=new Date().getMonth()+1; //定义月的变量的初始值
var ggWDay=new Array(37); //定义写日期的数组
function document.onclick() //任意点击时关闭该控件
{
with(window.event.srcElement)
{ if (tagName != "INPUT" && getAttribute("whatever")==null)
document.all.ggDateLayer.style.display="none";
}
}
function ggWriteHead(yy,mm) //往 head 中写入当前的年与月
{ document.all.ggYearHead.innerText = yy;
document.all.ggMonthHead.innerText = mm;
}
function tmpSelectYearInnerHTML(strYear) //年份的下拉框
{
if (strYear.match(/\D/)!=null){alert("年份输入参数不是数字!");return;}
var m = (strYear) ? strYear : new Date().getFullYear();
if (m < 1000 || m > 9999) {alert("年份值不在 1000 到 9999 之间!");return;}
var n = m - 10;
if (n < 1000) n = 1000;
if (n + 26 > 9999) n = 9974;
var s = "<select whatever=good name=tmpSelectYear style='font-size: 12px' "
s += "onblur='document.all.tmpSelectYearLayer.style.display=\"none\"' "
s += "onchange='document.all.tmpSelectYearLayer.style.display=\"none\";"
s += "ggTheYear = this.value; ggSetDay(ggTheYear,ggTheMonth)'>\r\n";
var selectInnerHTML = s;
for (var i = n; i < n + 26; i++)
{
if (i == m)
{selectInnerHTML += "<option value='" + i + "' selected>" + i + "年" + "</option>\r\n";}
else {selectInnerHTML += "<option value='" + i + "'>" + i + "年" + "</option>\r\n";}
}
selectInnerHTML += "</select>";
document.all.tmpSelectYearLayer.style.display="";
document.all.tmpSelectYearLayer.innerHTML = selectInnerHTML;
document.all.tmpSelectYear.focus();
}
function tmpSelectMonthInnerHTML(strMonth) //月份的下拉框
{
if (strMonth.match(/\D/)!=null){alert("月份输入参数不是数字!");return;}
var m = (strMonth) ? strMonth : new Date().getMonth() + 1;
var s = "<select whatever=good name=tmpSelectMonth style='font-size: 12px' "
s += "onblur='document.all.tmpSelectMonthLayer.style.display=\"none\"' "
s += "onchange='document.all.tmpSelectMonthLayer.style.display=\"none\";"
s += "ggTheMonth = this.value; ggSetDay(ggTheYear,ggTheMonth)'>\r\n";
var selectInnerHTML = s;
for (var i = 1; i < 13; i++)
{
if (i == m)
{selectInnerHTML += "<option value='"+i+"' selected>"+i+"月"+"</option>\r\n";}
else {selectInnerHTML += "<option value='"+i+"'>"+i+"月"+"</option>\r\n";}
}
selectInnerHTML += "</select>";
document.all.tmpSelectMonthLayer.style.display="";
document.all.tmpSelectMonthLayer.innerHTML = selectInnerHTML;
document.all.tmpSelectMonth.focus();
}
function closeLayer() //这个层的关闭
{
document.all.ggDateLayer.style.display="none";
}
function document.onkeydown()
{
if (window.event.keyCode==27)document.all.ggDateLayer.style.display="none";
}
function isLeapYear(year){
if(((year%4)==0)&&((year%100)!=0)||((year%400)==0)){
return(true);
}else{
return(false);
}
}
function GetMonthCount(year,month) //闰年二月为29天
{
var c=MonHead[month-1];if((month==2)&&isLeapYear(year)) c++;return c;
}
function GetDOW(day,month,year) //求某天的星期几
{
var dt=new Date(year,month-1,day).getDay()/7; return dt;
}
function ggPrevY() //上年
{
if(ggTheYear > 999 && ggTheYear <10000){ggTheYear--;}
else{alert("年份超出范围(1000-9999)!");}
ggSetDay(ggTheYear,ggTheMonth);
}
function ggNextY() //下年
{
if(ggTheYear > 999 && ggTheYear <10000){ggTheYear++;}
else{alert("年份超出范围(1000-9999)!");}
ggSetDay(ggTheYear,ggTheMonth);
}
function ggToday() //Today Button
{
ggTheYear = new Date().getFullYear();
ggTheMonth = new Date().getMonth()+1;
ggSetDay(ggTheYear,ggTheMonth);
}
function ggPrevM() //上月
{
if(ggTheMonth>1){ggTheMonth--}else{ggTheYear--;ggTheMonth=12;}
ggSetDay(ggTheYear,ggTheMonth);
}
function ggNextM() //下月
{
if(ggTheMonth==12){ggTheYear++;ggTheMonth=1}else{ggTheMonth++}
ggSetDay(ggTheYear,ggTheMonth);
}
function ggSetDay(yy,mm) //主要的写程序**********
{
ggWriteHead(yy,mm);
for (var i = 0; i < 37; i++){ggWDay[i]=""}; //将显示框的内容全部清空
var day1 = 1,firstday = new Date(yy,mm-1,1).getDay(); //某月第一天的星期几
for (var i = firstday; day1 < GetMonthCount(yy,mm)+1; i++){ggWDay[i]=day1;day1++;}
for (var i = 0; i < 37; i++)
{ var da = eval("document.all.ggDay"+i) //书写新的一个月的日期星期排列
if (ggWDay[i]!="")
{ da.innerHTML = "<b>" + ggWDay[i] + "</b>";
da.style.backgroundColor = (yy == new Date().getFullYear() &&
mm == new Date().getMonth()+1 && ggWDay[i] == new Date().getDate()) ? "#C9F1FA" : "#FF9900";
da.style.cursor="hand"
}
else{da.innerHTML="";da.style.backgroundColor="";da.style.cursor="default"}
}
}
function ggDayClick(n) //点击显示框选取日期,主输入函数*************
{
var yy = ggTheYear;
var mm = ggTheMonth;
if (mm < 10){mm = "0" + mm;}
if (outObject)
{
if (!n) {outObject.value=""; return;}
if ( n < 10){n = "0" + n;}
outObject.value= yy + "-" + mm + "-" + n ; //注:在这里你可以输出改成你想要的格式
closeLayer();
}
else {closeLayer(); alert("您所要输出的控件对象并不存在!");}
}
ggSetDay(ggTheYear,ggTheMonth);
注:onfocus="setday(this)"