<
script
type=
"text/javascript"
src=
"../../03-jQuery/js/jquery-1.10.2/jquery.js"
></
script
>
<?php
header
(
"Content-type:text/html;charset=utf-8"
);
/**
* Created by PhpStorm.
* User: lanouhn
* Date: 2017/8/24
* Time: 10:10
*/
//
获取当前的年
,
月
$year
=
isset
(
$_GET[
'year'
]
)
&& !
empty
(
$_GET[
'year'
]
)
?
$_GET[
'year'
]
:
date
(
'Y'
);
$month
=
isset
(
$_GET[
'month'
]
)
&& !
empty
(
$_GET[
'month'
]
)
?
$_GET[
'month'
]
:
date
(
'm'
);
//if (!is_numeric($year) || !is_numeric($month)){
// echo "<script>alert('
请输入数字
')</script>";
// $year = date('Y');
// $month = date('m');
//}
//
判断下一月
if
(
$month
==
12
)
{
//12
$next_month
=
1
;
$next_year
=
$year
+
1
;
}
else
{
//1-11
$next_month
=
$month
+
1
;
$next_year
=
$year
;
}
//
判断上一月
if
(
$month
==
1
)
{
//1
$last_month
=
12
;
$last_year
=
$year
-
1
;
}
else
{
//2-12
$last_month
=
$month
-
1
;
$last_year
=
$year
;
}
//
获取当月一共多少天
$days
=
date
(
't'
);
//
获取本月一号对应的是星期几
,
也就是说前面要有几个空
td
$weeks
=
date
(
'w'
,
mktime
(
0
,
0
,
0
,
$month
,
1
,
$year
));
//
获取当前月份的第几天
$day1
=
date
(
'd'
);
//
获取上个月的总天数
//$last_month = $month - 1;
$stamp
=
mktime
(
0
,
0
,
0
,
$last_month
,
1
,
$year
);
$last_days
=
date
(
't'
,
$stamp
);
//
判断空几格
if
(
$weeks
>
0
)
{
$l
=
$weeks
-
1
;
}
else
{
$l
=
6
;
}
$temp
=
$l
;
?>
<
style
>
.
last_month
{
color
:
#A9A9A9
;
}
td
{
border
:
1px solid
#646464
;
}
td
:
hover
{
border
:
1px solid
#ffd139
;
}
#btn
,.
btn
{
border-radius
:
5px
;
background-color
:
#ffd139
;
border-color
:
#f3e89b
;
}
caption a
{
text-decoration-line
:
none
;
color
:
#363636
;
font-weight
:
bold
;
}
caption a
:
hover
{
color
:
#6e6e6e
;
}
#year
,
#month
{
border-radius
:
3px
;
background-color
:
rgba
(
255
,
244
,
164
,
0.61
);
border-color
:
#f3e89b
;
}
</
style
>
<!--
表单
-->
<
form
action=
"10-Almanac.php"
id=
"form1"
>
<
input
type=
"text"
name=
"year"
placeholder=
"
请输入年
"
value=
"
<?php
echo
$year
?>
"
id=
"year"
>
<
input
type=
"text"
name=
"month"
placeholder=
"
请输入月
"
value=
"
<?php
echo
$month
?>
"
id=
"month"
>
<
input
type=
"button"
value=
"
提交
"
id=
"btn"
>
</
form
>
<
table
width=
"500"
border=
"1"
cellspacing=
"0"
cellpadding=
"0"
style=
"
text-align
:
center "
>
<
caption
style=
"
text-align
:
left
;
"
>
<?php
echo
$year
;
?>
年
<?php
echo
$month
;
?>
月
<
a
href=
"10-Almanac.php"
style=
"
float
:
right"
>
刷新
</
a
></
caption
>
<
tr
bgcolor=
"#bdb76b"
>
<
th
>
一
</
th
>
<
th
>
二
</
th
>
<
th
>
三
</
th
>
<
th
>
四
</
th
>
<
th
>
五
</
th
>
<
th
>
六
</
th
>
<
th
>
七
</
th
>
</
tr
>
<
tr
>
<!--{
里面加空格
?>
表示
1
号对应的星期几 前面要空格
-->
<?php
//
上个月天数
for
(
$j
=
$last_days
-
$l
+
1
;
$j
<=
$last_days
;
$j
++
)
{ ?>
<
td
class=
"last_month"
>
<?php
echo
$j
;
?>
</
td
>
<?php } ?>
<!--for
计算当前月份天数
-->
<?php
for
(
$i
=
1
;
$i
<=
$days
;
$i
++
)
{
//
添加背景颜色
if
(
$i
==
$day1
)
{
$color
=
"pink"
;
}
else
{
$color
=
"#999"
;
}?>
<!--
判断换行
-->
<?php
$l
++
;
?>
<?php
if
(
$l
%
7
==
0
)
{ ?>
<
td
bgcolor=
"
<?php
echo
$color
?>
"
>
<?php
echo
$i
;
?>
</
td
>
</
tr
>
<
tr
>
<?php }
else
{ ?>
<
td
bgcolor=
"
<?php
echo
$color
?>
"
>
<?php
echo
$i
;
?>
</
td
>
<?php } ?>
<?php } ?>
<!--
获取下个月剩余天数
-->
<?php
if
(
$temp
+
$days
<=
35
)
{
$total
=
35
;
}
else
{
$total
=
42
;
}
?>
<?php
for
(
$z
=
1
;
$z
<=
$total
-
$l
;
$z
++
)
{
?>
<?php
if
(
$l
%
7
==
0
)
{?>
<
td
class=
"last_month"
>
<?php
echo
$z
;
?>
</
td
>
</
tr
>
<
tr
>
<?php }
else
{?>
<
td
class=
"last_month"
>
<?php
echo
$z
;
?>
</
td
>
<?php }}?>
</
tr
>
<!--
上一页 下一页
-->
<
tr
>
<
td
colspan=
"7"
>
<
a
href=
"10-Almanac.php?month=
<?php
echo
$last_month
?>
&year=
<?php
echo
$last_year
?>
"
><
button
class=
"btn"
>
上一月
</
button
></
a
>
<
a
href=
"10-Almanac.php?month=
<?php
echo
$next_month
?>
&year=
<?php
echo
$next_year
?>
"
><
button
class=
"btn"
>
下一月
</
button
></
a
>
</
td
>
</
tr
>
</
table
>
<
script
>
$
(
'#btn'
).
click
(
function
()
{
$
(
'#form1'
).
submit
();
var
year
=
$
(
'#year'
).
val
();
var
month
=
$
(
'#month'
).
val
();
year
=
Number
(
year
);
month
=
Number
(
month
);
if
(
isNaN
(
year
)
||
year
==
0)
{
alert
(
'
请输入正确年份
!'
);
return false
;
}
if
(
isNaN
(
month
)
||
month
==
0)
{
alert
(
'
请输入正确月份
!'
);
return false
;
}
}
)
</
script
>