代码如下:
<script language='javascript' src='http://www.adsenser.org/js/calendar.js'></script> <input type="text" name=date title="单击弹出日历" style='width:80;cursor:pointer;' onfocus="javascript:calendar()">
[Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码]
其中用到一个Calendar.js文件代码如下:
<script language='javascript' src='http://www.adsenser.org/js/calendar.js'></script> <input type="text" name=date title="单击弹出日历" style='width:80;cursor:pointer;' onfocus="javascript:calendar()">
[Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码]
其中用到一个Calendar.js文件代码如下:
1
document.write("<divid=meizzCalendarLayerstyle='position:absolute;z-index:9999;width:144;height:193;display:none'>");
2
document.write("<iframename=meizzCalendarIframescrolling=noframeborder=0width=100%height=100%></iframe></div>");
3
functionwriteIframe(){
4
varstrIframe="<html><head><metahttp-equiv='Content-Type'content='text/html;charset=gb2312'><style>"+
5
"*{font-size:12px;font-family:宋体}"+
6
".bg{color:"+WebCalendar.lightColor+";cursor:default;background-color:"+WebCalendar.darkColor+";}"+
7
"table#tableMain{width:142;height:180;}"+
8
"table#tableWeektd{color:"+WebCalendar.lightColor+";}"+
9
"table#tableDaytd{font-weight:bold;}"+
10
"td#meizzYearHead,td#meizzYearMonth{color:"+WebCalendar.wordColor+"}"+
11
".out{text-align:center;border-top:1pxsolid"+WebCalendar.DarkBorder+";border-left:1pxsolid"+WebCalendar.DarkBorder+";"+
12
"border-right:1pxsolid"+WebCalendar.lightColor+";border-bottom:1pxsolid"+WebCalendar.lightColor+";}"+
13
".over{text-align:center;border-top:1pxsolid#FFFFFF;border-left:1pxsolid#FFFFFF;"+
14
"border-bottom:1pxsolid"+WebCalendar.DarkBorder+";border-right:1pxsolid"+WebCalendar.DarkBorder+"}"+
15
"input{border:1pxsolid"+WebCalendar.darkColor+";padding-top:1px;height:18;cursor:hand;"+
16
"color:"+WebCalendar.wordColor+";background-color:"+WebCalendar.btnBgColor+"}"+
17
"</style></head><bodyonselectstart='returnfalse'style='margin:0px'oncontextmenu='returnfalse'><formname=meizz>";
18
if(WebCalendar.drag){strIframe+="<scr"+"iptlanguage=javascript>"+
19
"vardrag=false,cx=0,cy=0,o=parent.WebCalendar.calendar;functiondocument.onmousemove(){"+
20
"if(parent.WebCalendar.drag&&drag){if(o.style.left=='')o.style.left=0;if(o.style.top=='')o.style.top=0;"+
21
"o.style.left=parseInt(o.style.left)+window.event.clientX-cx;"+
22
"o.style.top=parseInt(o.style.top)+window.event.clientY-cy;}}"+
23
"functiondocument.onkeydown(){switch(window.event.keyCode){case27:parent.hiddenCalendar();break;"+
24
"case37:parent.prevM();break;case38:parent.prevY();break;case39:parent.nextM();break;case40:parent.nextY();break;"+
25
"case84:document.forms[0].today.click();break;}window.event.keyCode=0;window.event.returnValue=false;}"+
26
"functiondragStart(){cx=window.event.clientX;cy=window.event.clientY;drag=true;}</scr"+"ipt>"}
27
strIframe+="<selectname=tmpYearSelectonblur='parent.hiddenSelect(this)'style='z-index:1;position:absolute;top:3;left:18;display:none'"+
28
"onchange='parent.WebCalendar.thisYear=this.value;parent.hiddenSelect(this);parent.writeCalendar();'></select>"+
29
"<selectname=tmpMonthSelectonblur='parent.hiddenSelect(this)'style='z-index:1;position:absolute;top:3;left:74;display:none'"+
30
"onchange='parent.WebCalendar.thisMonth=this.value;parent.hiddenSelect(this);parent.writeCalendar();'></select>"+
31
"<tableid=tableMainclass=bgborder=0cellspacing=2cellpadding=0>"+
32
"<tr><tdwidth=140height=19bgcolor='"+WebCalendar.lightColor+"'>"+
33
"<tablewidth=140id=tableHeadborder=0cellspacing=1cellpadding=0><tralign=center>"+
34
"<tdwidth=15height=19class=bgtitle='向前翻1月 快捷键:←'style='cursor:hand'onclick='parent.prevM()'><b><</b></td>"+
35
"<tdwidth=60id=meizzYearHeadtitle='点击此处选择年份'onclick='parent.funYearSelect(parseInt(this.innerText,10))'"+
36
"onmouseover='this.bgColor=parent.WebCalendar.darkColor;this.style.color=parent.WebCalendar.lightColor'"+
37
"onmouseout='this.bgColor=parent.WebCalendar.lightColor;this.style.color=parent.WebCalendar.wordColor'></td>"+
38
"<tdwidth=50id=meizzYearMonthtitle='点击此处选择月份'onclick='parent.funMonthSelect(parseInt(this.innerText,10))'"+
39
"onmouseover='this.bgColor=parent.WebCalendar.darkColor;this.style.color=parent.WebCalendar.lightColor'"+
40
"onmouseout='this.bgColor=parent.WebCalendar.lightColor;this.style.color=parent.WebCalendar.wordColor'></td>"+
41
"<tdwidth=15class=bgtitle='向后翻1月 快捷键:→'onclick='parent.nextM()'style='cursor:hand'><b>></b></td></tr></table>"+
42
"</td></tr><tr><tdheight=20><tableid=tableWeekborder=1width=140cellpadding=0cellspacing=0";
43
if(WebCalendar.drag){strIframe+="onmousedown='dragStart()'onmouseup='drag=false'onmouseout='drag=false'";}
44
strIframe+="borderColorLight='"+WebCalendar.darkColor+"'borderColorDark='"+WebCalendar.lightColor+"'>"+
45
"<tralign=center><tdheight=20>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr></table>"+
46
"</td></tr><tr><tdvalign=topwidth=140bgcolor='"+WebCalendar.lightColor+"'>"+
47
"<tableid=tableDayheight=120width=140border=0cellspacing=1cellpadding=0>";
48
for(varx=0;x<5;x++){strIframe+="<tr>";
49
for(vary=0;y<7;y++)strIframe+="<tdclass=outid='meizzDay"+(x*7+y)+"'></td>";strIframe+="</tr>";}
50
strIframe+="<tr>";
51
for(varx=35;x<39;x++)strIframe+="<tdclass=outid='meizzDay"+x+"'></td>";
52
strIframe+="<tdcolspan=3class=outtitle='"+WebCalendar.regInfo+"'><inputstyle='background-color:"+
53
WebCalendar.btnBgColor+";cursor:hand;padding-top:4px;width:100%;height:100%;border:0'onfocus='this.blur()'"+
54
"type=buttonvalue=' 关闭'onclick='parent.hiddenCalendar()'></td></tr></table>"+
55
"</td></tr><tr><tdheight=20width=140bgcolor='"+WebCalendar.lightColor+"'>"+
56
"<tableborder=0cellpadding=1cellspacing=0width=140>"+
57
"<tr><td><inputname=prevYeartitle='向前翻1年 快捷键:↑'onclick='parent.prevY()'type=buttonvalue='<<'"+
58
"onfocus='this.blur()'style='meizz:expression(this.disabled=parent.WebCalendar.thisYear==1000)'><input"+
59
"onfocus='this.blur()'name=prevMonthtitle='向前翻1月 快捷键:←'onclick='parent.prevM()'type=buttonvalue='< '>"+
60
"</td><tdalign=center><inputname=todaytype=buttonvalue='Today'onfocus='this.blur()'style='width:50'title='当前日期 快捷键:T'"+
61
"onclick=\"parent.returnDate(newDate().getDate()+'/'+(newDate().getMonth()+1)+'/'+newDate().getFullYear())\">"+
62
"</td><tdalign=right><inputtitle='向后翻1月 快捷键:→'name=nextMonthonclick='parent.nextM()'type=buttonvalue=' >'"+
63
"onfocus='this.blur()'><inputname=nextYeartitle='向后翻1年 快捷键:↓'onclick='parent.nextY()'type=buttonvalue='>>'"+
64
"onfocus='this.blur()'style='meizz:expression(this.disabled=parent.WebCalendar.thisYear==9999)'></td></tr></table>"+
65
"</td></tr><table></form></body></html>";
66
with(WebCalendar.iframe)
67
{
68
document.writeln(strIframe);document.close();
69
for(vari=0;i<39;i++)
70
{
71
WebCalendar.dayObj[i]=eval("meizzDay"+i);
72
WebCalendar.dayObj[i].onmouseover=dayMouseOver;
73
WebCalendar.dayObj[i].onmouseout=dayMouseOut;
74
WebCalendar.dayObj[i].onclick=returnDate;
75
}
76
}
77
}
78
functionWebCalendar()//初始化日历的设置
79
{
80
this.regInfo="WEBCalendarver3.0 关闭的快捷键:[Esc]";
81
this.daysMonth=newArray(31,28,31,30,31,30,31,31,30,31,30,31);
82
this.day=newArray(39);//定义日历展示用的数组
83
this.dayObj=newArray(39);//定义日期展示控件数组
84
this.dateStyle=null;//保存格式化后日期数组
85
this.objExport=null;//日历回传的显示控件
86
this.eventSrc=null;//日历显示的触发控件
87
this.inputDate=null;//转化外的输入的日期(d/m/yyyy)
88
this.thisYear=newDate().getFullYear();//定义年的变量的初始值
89
this.thisMonth=newDate().getMonth()+1;//定义月的变量的初始值
90
this.thisDay=newDate().getDate();//定义日的变量的初始值
91
this.today=this.thisDay+"/"+this.thisMonth+"/"+this.thisYear;//今天(d/m/yyyy)
92
this.iframe=window.frames("meizzCalendarIframe");//日历的iframe载体
93
this.calendar=getObjectById("meizzCalendarLayer");//日历的层
94
this.dateReg="";//日历格式验证的正则式
95
this.yearFall=50;//定义年下拉框的年差值
96
this.format="yyyy-mm-dd";//回传日期的格式
97
this.timeShow=false;//是否返回时间
98
this.drag=true;//是否允许拖动
99
this.darkColor="#408080";//控件的暗色
100
this.lightColor="#FFFFFF";//控件的亮色
101
this.btnBgColor="#ededed";//控件的按钮背景色
102
this.wordColor="#000000";//控件的文字颜色
103
this.wordDark="#DCDCDC";//控件的暗文字颜色
104
this.dayBgColor="#F5F5FA";//日期数字背景色
105
this.todayColor="#ff3300";//今天在日历上的标示背景色
106
this.DarkBorder="#D4D0C8";//日期显示的立体表达色
107
}varWebCalendar=newWebCalendar();
108
functioncalendar()//主调函数
109
{
110
vare=window.event.srcElement;
111
writeIframe();
112
varo=WebCalendar.calendar.style;WebCalendar.eventSrc=e;
113
if(arguments.length==0)WebCalendar.objExport=e;
114
elseWebCalendar.objExport=eval(arguments[0]);
115
WebCalendar.iframe.tableWeek.style.cursor=WebCalendar.drag?"move":"default";
116
vart=e.offsetTop,h=e.clientHeight,l=e.offsetLeft,p=e.type;
117
while(e=e.offsetParent){t+=e.offsetTop;l+=e.offsetLeft;}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117
