日期:2008-08-23  浏览次数:20985 次

这是对原日历控件做了改进,始之更符合中国人的习惯。改进后的代码如下面,将其存为rl.ASP然后在需要调用的文件中加入<!--#INCLUDE file="rl.ASP" -->,在控件中的调用如下,主要为onfocus和onblur事件<input name="gcrq" type="text" id="gcrq" value="<%=date(now)%>" onFocus="CreateMonthView(this)" onBlur="DeleteMonthView(this)">
rl.ASP主要内容
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<Script language="javascript">

<!--

//this is jsMonthView 1.0, author is Chinese DengKang (2002-07-12).

//I allow your do any modify, but i don't bear any liability.

//browser: IE 4 and later

function DefineMonthView(theTextObject){ //the month view construct function

this.GetOnlyName = function( ){ //create one and only name on the document

var theName = "MV"; //prefix

var aryName = new Array();

aryName[0] = "_MonthView"; //the month view main body's name postfix

aryName[1] = "_MonthGrid"; //the month view day area's name postfix

aryName[2] = "_goPreviousMonth"; //the month view go previous month button's name postfix

aryName[3] = "_goNextMonth"; //the month view go next month button's name postfix

aryName[4] = "_YearList"; //the month view year list's name postfix

aryName[5] = "_MonthList"; //the month view month list's name postfix

aryName[6] = "_DayList"; //keep the month view current day's element name postfix

var i = -1, j = 0, maxi = 2000;

var exTag = true;

while ((exTag == true) && (i < maxi)){

i++;

exTag = false;

for (j=0;j<aryName.length;j++){

if (document.all.item(theName + i.toString() + aryName[j]) != null){

exTag = true;

}

}

}

if (exTag == false){

return(theName + i.toString());

}else{

return("_" + theName);

}

}

var theName = this.GetOnlyName();

this.Name = theName; //the month view name

this.Source = theTextObject; //the month view act on theTextObject

this.MinYear = 1970; //year list min value

//return between 1000 and 9999 and <= this.MaxYear

this.MaxYear = 2030; //year list max value

//return between 1000 and 9999 and >= this.MinYear

this.Width = 200; //the month view main body's width

this.Height = 120; //the month view main body's height

this.DateFormat = "<yyyy>-<mm>-<dd>"; //the date format

//<yy> or <yyyy> is year, <m> or <mm> is digital format month, <MMM> or <MMMMMM> is character format month, <d> or <dd> is day, other char unchanged

//this function setting year, month and day sequence

//example:

// <yyyy>-<mm>-<dd> : 2002-04-01

// <yy>.<m>.<d> : 02.4.1

// <yyyy> Year <MMMMMM> Month <d> Day : 2002 Year April Month 1 Day

// <m>/<d>/<yy> : 4/1/02

// <MMM> <dd>, <yyyy> : Apr 01, 2002

// <MMMMMM> <d>, <yyyy> :