PHP系列之日历程序
【摘要】
<head><style>th{font-family:隶书;color:#0099ff;}table{background:#99ffcc;}#tr1{background:#00ccff;}.td1{color:#009999;}a{color:#ff9900;}</style></head><body><?php//php日历//1.date()函数获取当前...
-
<head>
-
<style>
-
th{font-family:隶书;color:#0099ff;}
-
table{background:#99ffcc;}
-
#tr1{background:#00ccff;}
-
.td1{color:#009999;}
-
a{color:#ff9900;}
-
</style>
-
</head>
-
<body>
-
<?php
-
//php日历
-
//1.date()函数获取当前的年月
-
$year=$_GET["y"]?$_GET["y"]:date("Y");
-
$mon=$_GET["m"]?$_GET["m"]:date("m");
-
//2.mktime()函数的使用,获取当前月的天数及当月1号的星期
-
$day=date("t",mktime(0,0,0,$mon,1,$year));
-
$w=date("w",mktime(0,0,0,$mon,1,$year));
-
//3.输出日历的头部信息
-
echo"<center>";
-
echo"<table border='0'>";
-
echo"<h3><font color='#00ff33'font-face='隶书'>{$year}年{$mon}月</font></h3>";
-
echo "<tr id='tr1'onmouseOver='overTr(this)'onmouseOut='outTr(this)'>";
-
echo "<th style='color:#ff0000;'onmouseOver='overTr(this)'onmouseOut='outTr(this)'>日</th>";
-
echo "<th class='td1'>一</th>";
-
echo "<th class='td1'>二</th>";
-
echo "<th class='td1'>三</th>";
-
echo "<th class='td1'>四</th>";
-
echo "<th class='td1'>五</th>";
-
echo "<th style='color:#ff0000;'>六</th>";
-
echo "</tr>";
-
//4.遍历输出日历
-
$d=1;
-
while($d<=$day){
-
echo"<tr onmouseOver='overTr(this)'onmouseOut='outTr(this)'>";
-
for($i=1;$i<=7;$i++){//循环输出7天信息
-
if($d<=$day&&($w<=$i||$d!=1)){
-
echo "<th>{$d}</th>";
-
$d++;
-
}else{
-
echo"<th> </th>";
-
}
-
}
-
}
-
//5.处理上下月,上下年的信息
-
$prey=$nexty=$year;
-
$prem=$nextm=$mon;
-
if($prem<=1){
-
$prem=12;
-
$prey--;
-
}else{
-
$prem--;
-
}
-
if($nextm>=12){
-
$nextm=1;
-
$nexty++;
-
}else{
-
$nextm++;
-
}
-
-
$prey=$year-1;//上一年
-
$nexty=$year+1;//上一月
-
//超链接
-
echo "<tr onmouseOver='overTr(this)'onmouseOut='outTr(this)'><td colspan='7'align='center'>";
-
-
echo"<a href='sy1.php?y={$prey}'><<</a> ";
-
echo "<font face='隶书'color='#663399'>{$year}年</font> ";
-
echo "<a href='sy1.php?y={$nexty}'>>></a> ";
-
-
echo" ";
-
-
echo"<a href='sy1.php?m={$prem}'><</a> ";
-
echo "<font face='隶书'color='#663399'>{$mon}月</font> ";
-
echo "<a href='sy1.php?m={$nextm}'>></a>";
-
-
echo "</td></tr>";
-
echo"</table>";
-
echo"</center>";
-
?>
-
-
<script type='text/JavaScript'>
-
var oriCol=null;
-
function overTr(obj){
-
oriCol=obj.bgColor;
-
obj.bgColor='#00ff99';
-
}
-
function outTr(obj){
-
obj.bgColor=oriCol;
-
}
-
-
</script>
-
</body>
-
</html>
文章来源: smilenicky.blog.csdn.net,作者:smileNicky,版权归原作者所有,如需转载,请联系作者。
原文链接:smilenicky.blog.csdn.net/article/details/50901069
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)