代码如下:
<script language='javascript' src='http://www.adsenser.org/js/calendar.js'></script>
<input type="text" name=date title="单击弹出日历" style='width:80;cursor:pointer;' οnfοcus="javascript:calendar()">
[Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码]
其中用到一个Calendar.js文件代码如下:
1
document.write(
"
<div id=meizzCalendarLayer style='position: absolute; z-index: 9999; width: 144; height: 193; display: none'>
"
);
2
document.write(
"
<iframe name=meizzCalendarIframe scrolling=no frameborder=0 width=100% height=100%></iframe></div>
"
);
3
function
writeIframe(){
4
var
strIframe
=
"
<html><head><meta http-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#tableWeek td{ color:
"
+
WebCalendar.lightColor
+
"
;}
"
+
9
"
table#tableDay td{ font-weight: bold;}
"
+
10
"
td#meizzYearHead, td#meizzYearMonth{color:
"
+
WebCalendar.wordColor
+
"
}
"
+
11
"
.out { text-align: center; border-top: 1px solid
"
+
WebCalendar.DarkBorder
+
"
; border-left: 1px solid
"
+
WebCalendar.DarkBorder
+
"
;
"
+
12
"
border-right: 1px solid
"
+
WebCalendar.lightColor
+
"
; border-bottom: 1px solid
"
+
WebCalendar.lightColor
+
"
;}
"
+
13
"
.over{ text-align: center; border-top: 1px solid #FFFFFF; border-left: 1px solid #FFFFFF;
"
+
14
"
border-bottom: 1px solid
"
+
WebCalendar.DarkBorder
+
"
; border-right: 1px solid
"
+
WebCalendar.DarkBorder
+
"
}
"
+
15
"
input{ border: 1px solid
"
+
WebCalendar.darkColor
+
"
; padding-top: 1px; height: 18; cursor: hand;
"
+
16
"
color:
"
+
WebCalendar.wordColor
+
"
; background-color:
"
+
WebCalendar.btnBgColor
+
"
}
"
+
17
"
</style></head><body onselectstart='return false' style='margin: 0px' οncοntextmenu='return false'><form name=meizz>
"
;
18
if
(WebCalendar.drag){ strIframe
+=
"
<scr
"
+
"
ipt language=javascript>
"
+
19
"
var drag=false, cx=0, cy=0, o = parent.WebCalendar.calendar; function document.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
"
function document.onkeydown(){ switch(window.event.keyCode){ case 27 : parent.hiddenCalendar(); break;
"
+
24
"
case 37 : parent.prevM(); break; case 38 : parent.prevY(); break; case 39 : parent.nextM(); break; case 40 : parent.nextY(); break;
"
+
25
"
case 84 : document.forms[0].today.click(); break;} window.event.keyCode = 0; window.event.returnValue= false;}
"
+
26
"
function dragStart(){cx=window.event.clientX; cy=window.event.clientY; drag=true;}</scr
"
+
"
ipt>
"
}
27
strIframe
+=
"
<select name=tmpYearSelect οnblur='parent.hiddenSelect(this)' style='z-index:1;position:absolute;top:3;left:18;display:none'
"
+
28
"
οnchange='parent.WebCalendar.thisYear =this.value; parent.hiddenSelect(this); parent.writeCalendar();'></select>
"
+
29
"
<select name=tmpMonthSelect οnblur='parent.hiddenSelect(this)' style='z-index:1; position:absolute;top:3;left:74;display:none'
"
+
30
"
οnchange='parent.WebCalendar.thisMonth=this.value; parent.hiddenSelect(this); parent.writeCalendar();'></select>
"
+
31
"
<table id=tableMain class=bg border=0 cellspacing=2 cellpadding=0>
"
+
32
"
<tr><td width=140 height=19 bgcolor='
"
+
WebCalendar.lightColor
+
"
'>
"
+
33
"
<table width=140 id=tableHead border=0 cellspacing=1 cellpadding=0><tr align=center>
"
+
34
"
<td width=15 height=19 class=bg title='向前翻 1 月 快捷键:←' style='cursor: hand' οnclick='parent.prevM()'><b><</b></td>
"
+
35
"
<td width=60 id=meizzYearHead title='点击此处选择年份' οnclick='parent.funYearSelect(parseInt(this.innerText, 10))'
"
+
36
"
οnmοuseοver='this.bgColor=parent.WebCalendar.darkColor; this.style.color=parent.WebCalendar.lightColor'
"
+
37
"
οnmοuseοut='this.bgColor=parent.WebCalendar.lightColor; this.style.color=parent.WebCalendar.wordColor'></td>
"
+
38
"
<td width=50 id=meizzYearMonth title='点击此处选择月份' οnclick='parent.funMonthSelect(parseInt(this.innerText, 10))'
"
+
39
"
οnmοuseοver='this.bgColor=parent.WebCalendar.darkColor; this.style.color=parent.WebCalendar.lightColor'
"
+
40
"
οnmοuseοut='this.bgColor=parent.WebCalendar.lightColor; this.style.color=parent.WebCalendar.wordColor'></td>
"
+
41
"
<td width=15 class=bg title='向后翻 1 月 快捷键:→' οnclick='parent.nextM()' style='cursor: hand'><b>></b></td></tr></table>
"
+
42
"
</td></tr><tr><td height=20><table id=tableWeek border=1 width=140 cellpadding=0 cellspacing=0
"
;
43
if
(WebCalendar.drag){strIframe
+=
"
οnmοusedοwn='dragStart()' οnmοuseup='drag=false' οnmοuseοut='drag=false'
"
;}
44
strIframe
+=
"
borderColorLight='
"
+
WebCalendar.darkColor
+
"
' borderColorDark='
"
+
WebCalendar.lightColor
+
"
'>
"
+
45
"
<tr align=center><td height=20>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr></table>
"
+
46
"
</td></tr><tr><td valign=top width=140 bgcolor='
"
+
WebCalendar.lightColor
+
"
'>
"
+
47
"
<table id=tableDay height=120 width=140 border=0 cellspacing=1 cellpadding=0>
"
;
48
for
(
var
x
=
0
; x
<
5
; x
++
){ strIframe
+=
"
<tr>
"
;
49
for
(
var
y
=
0
; y
<
7
; y
++
) strIframe
+=
"
<td class=out id='meizzDay
"
+
(x
*
7
+
y)
+
"
'></td>
"
; strIframe
+=
"
</tr>
"
;}
50
strIframe
+=
"
<tr>
"
;
51
for
(
var
x
=
35
; x
<
39
; x
++
) strIframe
+=
"
<td class=out id='meizzDay
"
+
x
+
"
'></td>
"
;
52
strIframe
+=
"
<td colspan=3 class=out title='
"
+
WebCalendar.regInfo
+
"
'><input style=' background-color:
"
+
53
WebCalendar.btnBgColor
+
"
;cursor: hand; padding-top: 4px; width: 100%; height: 100%; border: 0' οnfοcus='this.blur()'
"
+
54
"
type=button value=' 关闭' οnclick='parent.hiddenCalendar()'></td></tr></table>
"
+
55
"
</td></tr><tr><td height=20 width=140 bgcolor='
"
+
WebCalendar.lightColor
+
"
'>
"
+
56
"
<table border=0 cellpadding=1 cellspacing=0 width=140>
"
+
57
"
<tr><td><input name=prevYear title='向前翻 1 年 快捷键:↑' οnclick='parent.prevY()' type=button value='<<'
"
+
58
"
οnfοcus='this.blur()' style='meizz:expression(this.disabled=parent.WebCalendar.thisYear==1000)'><input
"
+
59
"
οnfοcus='this.blur()' name=prevMonth title='向前翻 1 月 快捷键:←' οnclick='parent.prevM()' type=button value='< '>
"
+
60
"
</td><td align=center><input name=today type=button value='Today' οnfοcus='this.blur()' style='width: 50' title='当前日期 快捷键:T'
"
+
61
"
οnclick=/
"
parent.returnDate(
new
Date().getDate()
+
'
/
'
+
(
new
Date().getMonth()
+
1
)
+
'
/
'
+
new
Date().getFullYear())/
"
>
"
+
62
"
</td><td align=right><input title='向后翻 1 月 快捷键:→' name=nextMonth οnclick='parent.nextM()' type=button value=' >'
"
+
63
"
οnfοcus='this.blur()'><input name=nextYear title='向后翻 1 年 快捷键:↓' οnclick='parent.nextY()' type=button value='>>'
"
+
64
"
οnfοcus='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
(
var
i
=
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
function
WebCalendar()
//
初始化日历的设置
79
{
80
this
.regInfo
=
"
WEB Calendar ver 3.0 关闭的快捷键:[Esc]
"
;
81
this
.daysMonth
=
new
Array(
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
);
82
this
.day
=
new
Array(
39
);
//
定义日历展示用的数组
83
this
.dayObj
=
new
Array(
39
);
//
定义日期展示控件数组
84
this
.dateStyle
=
null
;
//
保存格式化后日期数组
85
this
.objExport
=
null
;
//
日历回传的显示控件
86
this
.eventSrc
=
null
;
//
日历显示的触发控件
87
this
.inputDate
=
null
;
//
转化外的输入的日期(d/m/yyyy)
88
this
.thisYear
=
new
Date().getFullYear();
//
定义年的变量的初始值
89
this
.thisMonth
=
new
Date().getMonth()
+
1
;
//
定义月的变量的初始值
90
this
.thisDay
=
new
Date().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
}
var
WebCalendar
=
new
WebCalendar();
108
function
calendar()
//
主调函数
109
{
110
var
e
=
window.event.srcElement;
111
writeIframe();
112
var
o
=
WebCalendar.calendar.style; WebCalendar.eventSrc
=
e;
113
if
(arguments.length
==
0
) WebCalendar.objExport
=
e;
114
else
WebCalendar.objExport
=
eval(arguments[
0
]);
115
WebCalendar.iframe.tableWeek.style.cursor
=
WebCalendar.drag
?
"
move
"
:
"
default
"
;
116
var
t
=
e.offsetTop, h
=
e.clientHeight, l
=
e.offsetLeft, p
=
e.type;
117
while
(e
=
e.offsetParent){t
+=
e.offsetTop; l
+=
e.offsetLeft;}
118
o.display
=
""
; WebCalendar.iframe.document.body.focus();
119
var
cw
=
WebCalendar.calendar.clientWidth, ch
=
WebCalendar.calendar.clientHeight;
120
var
dw
=
document.body.clientWidth, dl
=
document.body.scrollLeft, dt
=
document.body.scrollTop;
121
122
if
(document.body.clientHeight
+
dt
-
t
-
h
>=
ch) o.top
=
(p
==
"
image
"
)
?
t
+
h : t
+
h
+
6
;
123
else
o.top
=
(t
-
dt
<
ch)
?
((p
==
"
image
"
)
?
t
+
h : t
+
h
+
6
) : t
-
ch;
124
if
(dw
+
dl
-
l
>=
cw) o.left
=
l;
else
o.left
=
(dw
>=
cw)
?
dw
-
cw
+
dl : dl;
125
if
(
!
WebCalendar.timeShow) WebCalendar.dateReg
=
/^
(/d{
1
,
4
})(
-|
/
/
)(/d{
1
,
2
})/
2
(/d{
1
,
2
})$
/
;
126
else
WebCalendar.dateReg
=
/^
(/d{
1
,
4
})(
-|
/
/
)(/d{
1
,
2
})/
2
(/d{
1
,
2
}) (/d{
1
,
2
}):(/d{
1
,
2
}):(/d{
1
,
2
})$
/
;
127
try
{
128
if
(WebCalendar.objExport.value.trim()
!=
""
){
129
WebCalendar.dateStyle
=
WebCalendar.objExport.value.trim().match(WebCalendar.dateReg);
130
if
(WebCalendar.dateStyle
==
null
)
131
{
132
WebCalendar.thisYear
=
new
Date().getFullYear();
133
WebCalendar.thisMonth
=
new
Date().getMonth()
+
1
;
134
WebCalendar.thisDay
=
new
Date().getDate();
135
alert(
"
原文本框里的日期有错误!/n可能与你定义的显示时分秒有冲突!
"
);
136
writeCalendar();
return
false
;
137
}
138
else
139
{
140
WebCalendar.thisYear
=
parseInt(WebCalendar.dateStyle[
1
],
10
);
141
WebCalendar.thisMonth
=
parseInt(WebCalendar.dateStyle[
3
],
10
);
142
WebCalendar.thisDay
=
parseInt(WebCalendar.dateStyle[
4
],
10
);
143
WebCalendar.inputDate
=
parseInt(WebCalendar.thisDay,
10
)
+
"
/
"
+
parseInt(WebCalendar.thisMonth,
10
)
+
"
/
"
+
144
parseInt(WebCalendar.thisYear,
10
); writeCalendar();
145
}
146
}
else
writeCalendar();
147
}
catch
(e){writeCalendar();}
148
}
149
function
funMonthSelect()
//
月份的下拉框
150
{
151
var
m
=
isNaN(parseInt(WebCalendar.thisMonth,
10
))
?
new
Date().getMonth()
+
1
: parseInt(WebCalendar.thisMonth);
152
var
e
=
WebCalendar.iframe.document.forms[
0
].tmpMonthSelect;
153
for
(
var
i
=
1
; i
<
13
; i
++
) e.options.add(
new
Option(i
+
"
月
"
, i));
154
e.style.display
=
""
; e.value
=
m; e.focus(); window.status
=
e.style.top;
155
}
156
function
funYearSelect()
//
年份的下拉框
157
{
158
var
n
=
WebCalendar.yearFall;
159
var
e
=
WebCalendar.iframe.document.forms[
0
].tmpYearSelect;
160
var
y
=
isNaN(parseInt(WebCalendar.thisYear,
10
))
?
new
Date().getFullYear() : parseInt(WebCalendar.thisYear);
161
y
=
(y
<=
1000
)
?
1000
: ((y
>=
9999
)
?
9999
: y);
162
var
min
=
(y
-
n
>=
1000
)
?
y
-
n :
1000
;
163
var
max
=
(y
+
n
<=
9999
)
?
y
+
n :
9999
;
164
min
=
(max
==
9999
)
?
max
-
n
*
2
: min;
165
max
=
(min
==
1000
)
?
min
+
n
*
2
: max;
166
for
(
var
i
=
min; i
<=
max; i
++
) e.options.add(
new
Option(i
+
"
年
"
, i));
167
e.style.display
=
""
; e.value
=
y; e.focus();
168
}
169
function
prevM()
//
往前翻月份
170
{
171
WebCalendar.thisDay
=
1
;
172
if
(WebCalendar.thisMonth
==
1
)
173
{
174
WebCalendar.thisYear
--
;
175
WebCalendar.thisMonth
=
13
;
176
}
177
WebCalendar.thisMonth
--
; writeCalendar();
178
}
179
function
nextM()
//
往后翻月份
180
{
181
WebCalendar.thisDay
=
1
;
182
if
(WebCalendar.thisMonth
==
12
)
183
{
184
WebCalendar.thisYear
++
;
185
WebCalendar.thisMonth
=
0
;
186
}
187
WebCalendar.thisMonth
++
; writeCalendar();
188
}
189
function
prevY(){WebCalendar.thisDay
=
1
; WebCalendar.thisYear
--
; writeCalendar();}
//
往前翻 Year
190
function
nextY(){WebCalendar.thisDay
=
1
; WebCalendar.thisYear
++
; writeCalendar();}
//
往后翻 Year
191
function
hiddenSelect(e){
for
(
var
i
=
e.options.length; i
>-
1
; i
--
)e.options.remove(i); e.style.display
=
"
none
"
;}
192
function
getObjectById(id){
if
(document.all)
return
(eval(
"
document.all.
"
+
id));
return
(eval(id)); }
193
function
hiddenCalendar(){getObjectById(
"
meizzCalendarLayer
"
).style.display
=
"
none
"
;};
194
function
appendZero(n){
return
((
"
00
"
+
n).substr((
"
00
"
+
n).length
-
2
));}
//
日期自动补零程序
195
function
String.prototype.trim(){
return
this
.replace(
/
(
^
/s
*
)
|
(/s
*
$)
/
g,
""
);}
196
function
dayMouseOver()
197
{
198
this
.className
=
"
over
"
;
199
this
.style.backgroundColor
=
WebCalendar.darkColor;
200
if
(WebCalendar.day[
this
.id.substr(
8
)].split(
"
/
"
)[
1
]
==
WebCalendar.thisMonth)
201
this
.style.color
=
WebCalendar.lightColor;
202
}
203
function
dayMouseOut()
204
{
205
this
.className
=
"
out
"
;
var
d
=
WebCalendar.day[
this
.id.substr(
8
)], a
=
d.split(
"
/
"
);
206
this
.style.removeAttribute('backgroundColor');
207
if
(a[
1
]
==
WebCalendar.thisMonth
&&
d
!=
WebCalendar.today)
208
{
209
if
(WebCalendar.dateStyle
&&
a[
0
]
==
parseInt(WebCalendar.dateStyle[
4
],
10
))
210
this
.style.color
=
WebCalendar.lightColor;
211
else
212
this
.style.color
=
WebCalendar.wordColor;
213
}
214
}
215
function
writeCalendar()
//
对日历显示的数据的处理程序
216
{
217
var
y
=
WebCalendar.thisYear;
218
var
m
=
WebCalendar.thisMonth;
219
var
d
=
WebCalendar.thisDay;
220
WebCalendar.daysMonth[
1
]
=
(
0
==
y
%
4
&&
(y
%
100
!=
0
||
y
%
400
==
0
))
?
29
:
28
;
221
if
(
!
(y
<=
9999
&&
y
>=
1000
&&
parseInt(m,
10
)
>
0
&&
parseInt(m,
10
)
<
13
&&
parseInt(d,
10
)
>
0
)){
222
alert(
"
对不起,你输入了错误的日期!
"
);
223
WebCalendar.thisYear
=
new
Date().getFullYear();
224
WebCalendar.thisMonth
=
new
Date().getMonth()
+
1
;
225
WebCalendar.thisDay
=
new
Date().getDate(); }
226
y
=
WebCalendar.thisYear;
227
m
=
WebCalendar.thisMonth;
228
d
=
WebCalendar.thisDay;
229
WebCalendar.iframe.meizzYearHead.innerText
=
y
+
"
年
"
;
230
WebCalendar.iframe.meizzYearMonth.innerText
=
parseInt(m,
10
)
+
"
月
"
;
231
WebCalendar.daysMonth[
1
]
=
(
0
==
y
%
4
&&
(y
%
100
!=
0
||
y
%
400
==
0
))
?
29
:
28
;
//
闰年二月为29天
232
var
w
=
new
Date(y, m
-
1
,
1
).getDay();
233
var
prevDays
=
m
==
1
?
WebCalendar.daysMonth[
11
] : WebCalendar.daysMonth[m
-
2
];
234
for
(
var
i
=
(w
-
1
); i
>=
0
; i
--
)
//
这三个 for 循环为日历赋数据源(数组 WebCalendar.day)格式是 d/m/yyyy
235
{
236
WebCalendar.day[i]
=
prevDays
+
"
/
"
+
(parseInt(m,
10
)
-
1
)
+
"
/
"
+
y;
237
if
(m
==
1
) WebCalendar.day[i]
=
prevDays
+
"
/
"
+
12
+
"
/
"
+
(parseInt(y,
10
)
-
1
);
238
prevDays
--
;
239
}
240
for
(
var
i
=
1
; i
<=
WebCalendar.daysMonth[m
-
1
]; i
++
) WebCalendar.day[i
+
w
-
1
]
=
i
+
"
/
"
+
m
+
"
/
"
+
y;
241
for
(
var
i
=
1
; i
<
39
-
w
-
WebCalendar.daysMonth[m
-
1
]
+
1
; i
++
)
242
{
243
WebCalendar.day[WebCalendar.daysMonth[m
-
1
]
+
w
-
1
+
i]
=
i
+
"
/
"
+
(parseInt(m,
10
)
+
1
)
+
"
/
"
+
y;
244
if
(m
==
12
) WebCalendar.day[WebCalendar.daysMonth[m
-
1
]
+
w
-
1
+
i]
=
i
+
"
/
"
+
1
+
"
/
"
+
(parseInt(y,
10
)
+
1
);
245
}
246
for
(
var
i
=
0
; i
<
39
; i
++
)
//
这个循环是根据源数组写到日历里显示
247
{
248
var
a
=
WebCalendar.day[i].split(
"
/
"
);
249
WebCalendar.dayObj[i].innerText
=
a[
0
];
250
WebCalendar.dayObj[i].title
=
a[
2
]
+
"
-
"
+
appendZero(a[
1
])
+
"
-
"
+
appendZero(a[
0
]);
251
WebCalendar.dayObj[i].bgColor
=
WebCalendar.dayBgColor;
252
WebCalendar.dayObj[i].style.color
=
WebCalendar.wordColor;
253
if
((i
<
10
&&
parseInt(WebCalendar.day[i],
10
)
>
20
)
||
(i
>
27
&&
parseInt(WebCalendar.day[i],
10
)
<
12
))
254
WebCalendar.dayObj[i].style.color
=
WebCalendar.wordDark;
255
if
(WebCalendar.inputDate
==
WebCalendar.day[i])
//
设置输入框里的日期在日历上的颜色
256
{WebCalendar.dayObj[i].bgColor
=
WebCalendar.darkColor; WebCalendar.dayObj[i].style.color
=
WebCalendar.lightColor;}
257
if
(WebCalendar.day[i]
==
WebCalendar.today)
//
设置今天在日历上反应出来的颜色
258
{WebCalendar.dayObj[i].bgColor
=
WebCalendar.todayColor; WebCalendar.dayObj[i].style.color
=
WebCalendar.lightColor;}
259
}
260
}
261
function
returnDate()
//
根据日期格式等返回用户选定的日期
262
{
263
if
(WebCalendar.objExport)
264
{
265
var
returnValue;
266
var
a
=
(arguments.length
==
0
)
?
WebCalendar.day[
this
.id.substr(
8
)].split(
"
/
"
) : arguments[
0
].split(
"
/
"
);
267
var
d
=
WebCalendar.format.match(
/^
(/w{
4
})(
-|
/
/
)(/w{
1
,
2
})/
2
(/w{
1
,
2
})$
/
);
268
if
(d
==
null
){alert(
"
你设定的日期输出格式不对!/r/n/r/n请重新定义 WebCalendar.format !
"
);
return
false
;}
269
var
flag
=
d[
3
].length
==
2
||
d[
4
].length
==
2
;
//
判断返回的日期格式是否要补零
270
returnValue
=
flag
?
a[
2
]
+
d[
2
]
+
appendZero(a[
1
])
+
d[
2
]
+
appendZero(a[
0
]) : a[
2
]
+
d[
2
]
+
a[
1
]
+
d[
2
]
+
a[
0
];
271
if
(WebCalendar.timeShow)
272
{
273
var
h
=
new
Date().getHours(), m
=
new
Date().getMinutes(), s
=
new
Date().getSeconds();
274
returnValue
+=
flag
?
"
"
+
appendZero(h)
+
"
:
"
+
appendZero(m)
+
"
:
"
+
appendZero(s) :
"
"
+
h
+
"
:
"
+
m
+
"
:
"
+
s;
275
}
276
WebCalendar.objExport.value
=
returnValue;
277
hiddenCalendar();
278
}
279
}
280
function
document.onclick()
281
{
282
if
(WebCalendar.eventSrc
!=
window.event.srcElement) hiddenCalendar();
283
}
284
285
286
/*
jeff add
287
日期输入控件的控制函数
288
*/
289
function
makeDate(Obj)
290
{
291
var
y
=
eval(
"
document.all.
"
+
Obj
+
"
YearInput
"
).value;
292
var
m
=
eval(
"
document.all.
"
+
Obj
+
"
MonthInput
"
).value;
293
var
d
=
eval(
"
document.all.
"
+
Obj
+
"
DayInput
"
).value;
294
//
使用 datetime 数据类型存储从 1753 年 1 月 1 日至 9999 年 12 月 31 日的日期
295
if
(isDate(y,m,d)
&&
y
>=
1753
)
296
{
297
eval(
"
document.all.
"
+
Obj).value
=
y
+
"
-
"
+
m
+
"
-
"
+
d;
298
}
299
else
300
{
301
if
(y
!=
""
||
m
!=
""
||
d
!=
""
)
302
return
false
;
303
eval(
"
document.all.
"
+
Obj).value
=
""
;
304
}
305
return
true
;
306
}
307
function
splitDate(Obj)
308
{
309
var
dt
=
eval(
"
document.all.
"
+
Obj).value;
310
eval(
"
document.all.
"
+
Obj
+
"
YearInput
"
).value
=
dt.substring(
0
,dt.indexOf(
"
-
"
));
311
eval(
"
document.all.
"
+
Obj
+
"
MonthInput
"
).value
=
dt.substring(dt.indexOf(
"
-
"
)
+
1
,dt.lastIndexOf(
"
-
"
));
312
eval(
"
document.all.
"
+
Obj
+
"
DayInput
"
).value
=
dt.substring(dt.lastIndexOf(
"
-
"
)
+
1
);
313
}
314
function
isDate(year,month,day)
315
{
316
month
=
month
-
1
;
317
var
dt
=
new
Date(year,month,day);
318
if
(year
==
dt.getFullYear()
&&
month
==
dt.getMonth()
&&
day
==
dt.getDate())
319
return
true
;
320
else
321
return
false
;
322
}
323
324
//
显示日期输入控件(输入框名称,初始日期值,是否需要日历控件)
325
function
writeDateInput(inputName,inputValue,needCalendar)
326
{
327
var
dateInput
=
"
<table cellspacing=0 cellpadding=0><tr><td><div class=cBoxnosize style='width:80'>
"
+
328
"
<input class=yearInput type=text name=
"
+
inputName
+
"
YearInput size=4 maxlength=4 οnkeydοwn=/
"
if
(event.keyCode
==
39
)event.keyCode
=
9
;/
"
onpropertychange=/
"
if
(value.length
==
4
)
this
.nextSibling.nextSibling.select();/
"
οnblur=/
"
if
(value.search(
/
[
^
0
-
9
]
/
)
>-
1
){alert('请输入数字');
this
.select();}/
"
>
"
+
329
"
-<input class=monthInput type=text name=
"
+
inputName
+
"
MonthInput size=2 maxlength=2 οnkeydοwn=/
"
if
(event.keyCode
==
39
)event.keyCode
=
9
;
if
(event.keyCode
==
37
)
this
.previousSibling.previousSibling.select();/
"
onpropertychange=/
"
if
(value.length
==
2
)
this
.nextSibling.nextSibling.select();/
"
οnblur=/
"
if
(value.search(
/
[
^
0
-
9
]
/
)
>-
1
){alert('请输入数字');
this
.select();}/
"
>
"
+
330
"
-<input class=dayInput type=text name=
"
+
inputName
+
"
DayInput size=2 maxlength=2 οnkeydοwn=/
"
if
(event.keyCode
==
37
)
this
.previousSibling.previousSibling.select();/
"
οnblur=/
"
if
(value.search(
/
[
^
0
-
9
]
/
)
>-
1
){alert('请输入数字');
this
.select();}/
"
>
"
+
331
"
<input type=hidden name=
"
+
inputName
+
"
onpropertychange=/
"
splitDate('
"
+inputName+
"
')/
"
>
"
;
332
if
(needCalendar
==
true
)
333
dateInput
=
dateInput
+
"
</div></td><td> <input type=button value=/
"
日期/
"
οnclick=/
"
if
(
!
makeDate('
"
+inputName+
"
'))alert('对不起,你输入了错误的日期!');calendar(document.all.
"
+inputName+
"
);/
"
class=cButton></td></tr></table>
"
;
334
else
335
dateInput
=
dateInput
+
"
</div></td></tr></table>
"
;
336
document.writeln(dateInput);
337
if
(inputValue
!=
""
)
338
eval(
"
document.all.
"
+
inputName).value
=
inputValue;
339
}
340
341
function
writeDateInputs(inputName,inputId,inputValue,needCalendar)
342
{
343
var
dateInput
=
"
<table><tr><td><div class=cBoxnosize style='width:80'>
"
+
344
"
<input class=yearInput type=text name=
"
+
inputId
+
"
YearInput size=4 maxlength=4 οnkeydοwn=/
"
if
(event.keyCode
==
39
)event.keyCode
=
9
;/
"
onpropertychange=/
"
if
(value.length
==
4
)
this
.nextSibling.nextSibling.select();/
"
οnblur=/
"
if
(value.search(
/
[
^
0
-
9
]
/
)
>-
1
){alert('请输入数字');
this
.select();}/
"
>
"
+
345
"
-<input class=monthInput type=text name=
"
+
inputId
+
"
MonthInput size=2 maxlength=2 οnkeydοwn=/
"
if
(event.keyCode
==
39
)event.keyCode
=
9
;
if
(event.keyCode
==
37
)
this
.previousSibling.previousSibling.select();/
"
onpropertychange=/
"
if
(value.length
==
2
)
this
.nextSibling.nextSibling.select();/
"
οnblur=/
"
if
(value.search(
/
[
^
0
-
9
]
/
)
>-
1
){alert('请输入数字');
this
.select();}/
"
>
"
+
346
"
-<input class=dayInput type=text name=
"
+
inputId
+
"
DayInput size=2 maxlength=2 οnkeydοwn=/
"
if
(event.keyCode
==
37
)
this
.previousSibling.previousSibling.select();/
"
οnblur=/
"
if
(value.search(
/
[
^
0
-
9
]
/
)
>-
1
){alert('请输入数字');
this
.select();}/
"
>
"
+
347
"
<input type=hidden name=
"
+
inputName
+
"
id=
"
+
inputId
+
"
onpropertychange=/
"
splitDate('
"
+inputId+
"
')/
"
>
"
;
348
if
(needCalendar
==
true
)
349
dateInput
=
dateInput
+
"
</div></td><td><input type=button value=/
"
日期/
"
οnclick=/
"
if
(
!
makeDate('
"
+inputId+
"
'))alert('对不起,你输入了错误的日期!');calendar(document.all.
"
+inputId+
"
);/
"
class=cButton></td></tr></table>
"
;
350
else
351
dateInput
=
dateInput
+
"
</div></td></tr></table>
"
;
352
document.writeln(dateInput);
353
if
(inputValue
!=
""
)
354
eval(
"
document.all.
"
+
inputId).value
=
inputValue;
355
}