<!
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"
>
<
html
>
<
head
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=UTF-8"
>
<
title
>
周选择工具
</
title
>
</
head
>
<
body
>
<
input
name
="weekPicker"
readonly
="readonly"
type
="text"
id
="weekPicker"
style
="width:150px"
>
<
input
type
="button"
name
="Submit"
value
="上一周"
onClick
="javascript:pickWeek(-1)"
>
<
input
type
="button"
name
="Submit2"
value
="下一周"
onClick
="javascript:pickWeek(1)"
>
<
script
type
="text/javascript"
>
function
getThisWeek(year,month,day)
{
var
today
=
new
Date(year,month
-
1
,day);
var
week
=
today.getDay();
if
(week
==
0
)
{
week
=
7
;
}
var
monday
=
new
Date(today.valueOf()
-
(week
-
1
)
*
24
*
60
*
60
*
1000
);
var
sunday
=
new
Date(monday.valueOf()
+
6
*
24
*
60
*
60
*
1000
);
return
monday.getFullYear()
+
"
-
"
+
((monday.getMonth()
+
1
).toString().length
==
1
?
(
"
0
"
+
(monday.getMonth()
+
1
)):(monday.getMonth()
+
1
))
+
"
-
"
+
(monday.getDate().toString().length
==
1
?
"
0
"
+
monday.getDate():monday.getDate())
+
"
到
"
+
sunday.getFullYear()
+
"
-
"
+
((sunday.getMonth()
+
1
).toString().length
==
1
?
(
"
0
"
+
(sunday.getMonth()
+
1
)):(sunday.getMonth()
+
1
))
+
"
-
"
+
(sunday.getDate().toString().length
==
1
?
"
0
"
+
sunday.getDate():sunday.getDate());
}
function
getPreviousWeek(year,month,day)
{
var
today
=
new
Date(year,month
-
1
,day);
var
week
=
today.getDay();
if
(week
==
0
)
{
week
=
7
;
}
var
monday
=
new
Date(today.valueOf()
-
(week
+
6
)
*
24
*
60
*
60
*
1000
);
var
sunday
=
new
Date(monday.valueOf()
+
6
*
24
*
60
*
60
*
1000
);
return
monday.getFullYear()
+
"
-
"
+
((monday.getMonth()
+
1
).toString().length
==
1
?
(
"
0
"
+
(monday.getMonth()
+
1
)):(monday.getMonth()
+
1
))
+
"
-
"
+
(monday.getDate().toString().length
==
1
?
"
0
"
+
monday.getDate():monday.getDate())
+
"
到
"
+
sunday.getFullYear()
+
"
-
"
+
((sunday.getMonth()
+
1
).toString().length
==
1
?
(
"
0
"
+
(sunday.getMonth()
+
1
)):(sunday.getMonth()
+
1
))
+
"
-
"
+
(sunday.getDate().toString().length
==
1
?
"
0
"
+
sunday.getDate():sunday.getDate());
}
function
getNextWeek(year,month,day)
{
var
today
=
new
Date(year,month
-
1
,day);
var
week
=
today.getDay();
if
(week
==
0
)
{
week
=
7
;
}
var
monday
=
new
Date(today.valueOf()
-
(week
-
8
)
*
24
*
60
*
60
*
1000
);
var
sunday
=
new
Date(monday.valueOf()
+
6
*
24
*
60
*
60
*
1000
);
return
monday.getFullYear()
+
"
-
"
+
((monday.getMonth()
+
1
).toString().length
==
1
?
(
"
0
"
+
(monday.getMonth()
+
1
)):(monday.getMonth()
+
1
))
+
"
-
"
+
(monday.getDate().toString().length
==
1
?
"
0
"
+
monday.getDate():monday.getDate())
+
"
到
"
+
sunday.getFullYear()
+
"
-
"
+
((sunday.getMonth()
+
1
).toString().length
==
1
?
(
"
0
"
+
(sunday.getMonth()
+
1
)):(sunday.getMonth()
+
1
))
+
"
-
"
+
(sunday.getDate().toString().length
==
1
?
"
0
"
+
sunday.getDate():sunday.getDate());
}
function
pickWeek(id)
{
var
year;
var
month;
var
day;
if
(id
==
0
)
{
var
today
=
new
Date();
year
=
today.getYear();
month
=
today.getMonth()
+
1
;
day
=
today.getDate();
}
else
{
var
today
=
document.getElementById(
"
weekPicker
"
).value.split(
"
到
"
)[
0
].split(
"
-
"
);
year
=
today[
0
];
month
=
today[
1
];
day
=
today[
2
];
}
switch
(id)
{
case
0
:
{
document.getElementById(
"
weekPicker
"
).value
=
getThisWeek(year,month,day);
break
;
}
case
1
:
{
document.getElementById(
"
weekPicker
"
).value
=
getNextWeek(year,month,day);
break
;
}
case
-
1
:
{
document.getElementById(
"
weekPicker
"
).value
=
getPreviousWeek(year,month,day);
break
;
}
}
}
pickWeek(
0
);
</
script
>
</
body
>
</
html
>
posted on 2007-12-18 11:48
xiaosilent 阅读(2244)
评论(0) 编辑 收藏