<HEAD>
<TITLE>最精致的日历式日期输入控件 (Smart Ver 1.00)</TITLE>
</HEAD>
<style>
body
{
font-size:12px;
font-family:"Tahoma";
}
td
{
font-size:12px;
font-family:"Tahoma";
}
.inputdate
{
border:1px solid #7287c6;
text-align: center;
font-size: 12px;
font-style: normal;
height: 16px;
}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
/********************************************************************
more javascript from http://www.smallrain.net
时间:2004-01-01
作者:Smart
功能:日历式日期选择控件
参数:
说明:
1.输入框直接调用用以下代码
<Script>DateBox("InputName","DateValue")<\/Script>
其中:InputName 为输入日期的文本框.注:不能为空.
DateValue 为输入日期的文本框默认日期值.格式为:YYYY-MM-DD.如2004-01-01
此值可以不填或为空.则默认值为当天日期.(客户端)
2.其它"按钮"调用用以下代码
CallDate("InputName")
其中:InputName 为输入日期的文本框.注:不能为空.
修改区
时间:
修改人:
原因:
********************************************************************/
/*基本参数*/
var Frw=106; //日历宽度
var Frh=137; //日历高度
var Frs=4; //影子大小
var Hid=true;//日历是否打开
/*创建框架*/
document.writeln('<Div id=Calendar Author=smart scrolling="no" frameborder=0 style="border:0px solid #EEEEEE ;position: absolute; width: '+Frw+'; height: '+Frh+'; z-index: 0; filter :\'progid:DXImageTransform.Microsoft.Shadow(direction=135,color=#AAAAAA,strength='+Frs+')\' ;display: none"></Div>');
/*取得今日日期*/
function GetTodayDate()
{
today= new Date();
y= today.getYear();
m= (today.getMonth() + 1);
if (m<10)
{
m='0'+m;
}
d= today.getDate();
if (d<10)
{
d='0'+d;
}
return y+'-'+m+'-'+d
}
/*输入今天日期*/
function SetTodayDate(InputBox)
{
HiddenCalendar();
InputBox.value=GetTodayDate();
}
/*取某年某月第一天的星期值(月份-1)*/
function GetFirstWeek(The_Year,The_Month)
{
return (new Date(The_Year,The_Month-1,1)).getDay()
}
/*取某年某月中总天数*/
function GetThisDays(The_Year,The_Month)
{
return (new Date(The_Year,The_Month,0)).getDate()
}
/*取某年某月上个月中总天数*/
function GetLastDays(The_Year,The_Month)
{
return (new Date(The_Year,The_Month-1,0)).getDate()
}
/*判断是否是闰年*/
function RunNian(The_Year)
{
if ((The_Year%400==0) || ((The_Year%4==0) && (The_Year%100!=0)))
return true;
else
return false;
}
/* 判断日期(YYYY-MM-DD)的日期是否正确 */
function DateIsTrue(asDate){
var lsDate = asDate + "";
var loDate = lsDate.split("-");
if (loDate.length!=3) return false;
var liYear = parseFloat(loDate[0]);
var liMonth = parseFloat(loDate);
var liDay = parseFloat(loDate);
if ((loDate[0].length>4)||(loDate.length>2)||(loDate.length>2)) return false;
if (isNaN(liYear)||isNaN(liMonth)||isNaN(liDay)) return false;
if ((liYear<1800)||(liYear>2500)) return false;
if ((liMonth>12)||(liMonth<=0)) return false;
if (GetThisDays(liYear,liMonth)<liDay) return false;
return !isNaN(Date.UTC(liYear,liMonth,liDay));
}
/*取某年某月的周值*/
function GetCountWeeks(The_Year,The_Month)
{
var Allday;
Allday = 0;
if (The_Year>2000)
{
for (i=2000 ;i<The_Year; i++)
if (RunNian(i))
Allday += 366;
else
Allday += 365;
for (i=2; i<=The_Month; i++)
{
switch (i)
{
case 2 :
if (RunNian(The_Year))
Allday += 29;
else
Allday += 28;
break;
case 3 : Allday += 31; break;
case 4 : Allday += 30; break;
case 5 : Allday += 31; break;
case 6 : Allday += 30; break;
case 7 : Allday += 31; break;
case 8 : Allday += 31; break;
case 9 : Allday += 30; break;
case 10 : Allday += 31; break;
case 11 : Allday += 30; break;
case 12 : Allday += 31; break;
}
}
}
return (Allday+6)%7;
}
/*输入框显示*/
function InputValue(InputBox,Year,Month,Day)
{
if (Month<10)
{
Month='0'+Month
}
if (Day<10)
{
Day='0'+Day
}
InputBox.value=Year+"-"+Month+"-"+Day
}
//上一月
function ForwardMonth(InputBox,Year,Month,Day)
{
Month=Month-1;
if (Month<1)
{
Month=12;
Year=Year-1;
if (Year<1800)
Year=2500;
}
Day=((GetThisDays(Year,Month)<Day)?GetThisDays(Year,Month):Day)
Hid=false;
ShowCalendar(InputBox,Year,Month,Day)
}
//下一月
function NextMonth(InputBox,Year,Month,Day)
{
Month=Month+1;
if (Month>12)
{
Month=1;
Year=Year+1;
if (Year>2500)
Year=1800;
}
Day=((GetThisDays(Year,Month)<Day)?GetThisDays(Year,Month):Day)
Hid=false;
ShowCalendar(InputBox,Year,Month,Day)
}
//上一年
function ForwardYear(InputBox,Year,Month,Day)
{
Year=Year-1;
if (Year<1800)
Year=2500;
Day=((GetThisDays(Year,Month)<Day)?GetThisDays(Year,Month):Day)
Hid=false;
ShowCalendar(InputBox,Year,Month,Day)
}
//下一年
function NextYear(InputBox,Year,Month,Day)
{
Year=Year+1;
if (Year>2500)
Year=1800;
Day=((GetThisDays(Year,Month)<Day)?GetThisDays(Year,Month):Day)
Hid=false;
ShowCalendar(InputBox,Year,Month,Day)
}
/*其它事件显示日历*/
function OpenDate(where)
{
GetCalendar(where)
}
/*根据输入框中的日期显示日历*/
function GetCalendar(where)
{
Hid=false;
var Box_Name=where.name;
var Box_value=where.value;
if (DateIsTrue(Box_value))