这个插件我试验了下,发现问题如下:
①在年月跳转的时候代码有个<a href='sy1.php?y={$nexty}'>>></a> ,但是没有sy1.php文件存在,可以改为当前文件calendar.php。
②跳转后譬如现在是2018年5月, 我切换为2018年6月之后选择其中一天,年月表会回到初始值2018年5月.求大神解答谢谢
//修复问题②
改动后代码如下:
<!DOCTYPE html>
<html>
<style>
table{background:#99ffcc;}
th{font-family:隶书;color:#0099ff;}
#tr1{background:#00ccff;}
.td1{color:#009999;}
a{color:#ff9900;}
</style>
<head>
<meta charset="UTF-8">
<script src="jquery-2.2.3.js" type="text/javascript"></script>
</head>
<body>
<?php
require "./Convert.class.php";
$convert=isset($_GET["convert"])?$_GET["convert"]:date("Y-m-d");
//php日历
//1.date()函数获取当前的年月日
$year=isset($_GET["y"])?$_GET["y"]:date("Y");
$mon=isset($_GET["m"])?$_GET["m"]:date("m");
$day=isset($_GET["d"])?$_GET["d"]:date("d");
$convert=$year.'-'.$mon.'-'.$day;//组装日期格式
if($convert!=''){
$c=new Convert($convert);
$time=$c->getLyTime();//得到阴历时间
// echo $convert.'对应的农历时间:'.$time;
}
//2.mktime()函数的使用,获取当前月的天数及当月1号的星期
$daynum=date("t",mktime(0,0,0,$mon,1,$year));//当前月的天数 31
$w=date("w",mktime(0,0,0,$mon,1,$year));//当月1号的星期几 4
//3.输出日历的头部信息
echo"<div>";
echo"<table border='0'>";
echo"<h3><div>{$year}年{$mon}月{$day}日</div></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>一</th>";
echo "<th>二</th>";
echo "<th>三</th>";
echo "<th>四</th>";
echo "<th>五</th>";
echo "<th style='color:#ff0000;'>六</th>";
echo "</tr>";
//4.遍历输出日历
$dayindex=1;
while($dayindex<=$daynum){
echo"<tr onmouseOver='overTr(this)'onmouseOut='outTr(this)'>";
for($i=1;$i<=7;$i++){//循环输出7天信息
if($dayindex<=$daynum&&($w<$i||$dayindex!=1)){
//'2014-10-1'(传入这样一个字符串)$year-$month-$d
if($dayindex==$day){
echo "<th style='background:#ff0000;'><a href='?y={$year}&m={$mon}&d={$dayindex}'>{$dayindex}</a></th>";
}else{
echo "<th onmouseOver='overTh(this)' onmouseOut='outTh(this)'><a href='?y={$year}&m={$mon}&d={$dayindex}'>{$dayindex}</a></th>";
$dayindex++;
echo"<th> </th>";
//5.处理上下月,上下年的信息
$prey=$nexty=$year;
$prem=$nextm=$mon;
if($prem<=1){
$prem=12;
$prey--;
$prem--;
if($nextm>=12){
$nextm=1;
$nexty++;
$nextm++;
$prey=$year-1;//上一年
$nexty=$year+1;//下一年
//超链接
echo "<tr onmouseOver='overTr(this)'onmouseOut='outTr(this)'><td colspan='7'align='center'>";
echo"<a href='calendar.php?y={$prey}&m={$mon}&d={$day}'><<</a> ";
echo "<font face='隶书'color='#663399'>{$year}年</font> ";
echo "<a href='calendar.php?y={$nexty}&m={$mon}&d={$day}'>>></a> ";
echo" ";
echo"<a href='calendar.php?y={$year}&m={$prem}&d={$day}'><</a> ";
echo "{$mon}月";
echo "echo "</td></tr>"; echo "<tr onmouseOver= 'overTr(this)'onmouseOut='outTr(this)'>
echo "</td></tr>";
echo "<tr onmouseOver= 'overTr(this)'onmouseOut='outTr(this)'>
echo "
echo "</table>";
echo "</div>";
?>
<script>
var oriCol=null;
function overTr(obj){
oriCol=obj.bgColor;
obj.bgColor='#0f0';
function outTr(obj){
obj.bgColor =oriCol;
function overTh(obj) {
obj.bgColor='red';
function outTh(obj){
obj.bgColor=oriCol ;
//修复问题②
改动后代码如下:
<!DOCTYPE html>
<html>
<style>
table{background:#99ffcc;}
th{font-family:隶书;color:#0099ff;}
#tr1{background:#00ccff;}
.td1{color:#009999;}
a{color:#ff9900;}
</style>
<head>
<meta charset="UTF-8">
<script src="jquery-2.2.3.js" type="text/javascript"></script>
</head>
<body>
<?php
require "./Convert.class.php";
$convert=isset($_GET["convert"])?$_GET["convert"]:date("Y-m-d");
//php日历
//1.date()函数获取当前的年月日
$year=isset($_GET["y"])?$_GET["y"]:date("Y");
$mon=isset($_GET["m"])?$_GET["m"]:date("m");
$day=isset($_GET["d"])?$_GET["d"]:date("d");
$convert=$year.'-'.$mon.'-'.$day;//组装日期格式
if($convert!=''){
$c=new Convert($convert);
$time=$c->getLyTime();//得到阴历时间
// echo $convert.'对应的农历时间:'.$time;
}
//2.mktime()函数的使用,获取当前月的天数及当月1号的星期
$daynum=date("t",mktime(0,0,0,$mon,1,$year));//当前月的天数 31
$w=date("w",mktime(0,0,0,$mon,1,$year));//当月1号的星期几 4
//3.输出日历的头部信息
echo"<div>";
echo"<table border='0'>";
echo"<h3><div>{$year}年{$mon}月{$day}日</div></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>一</th>";
echo "<th>二</th>";
echo "<th>三</th>";
echo "<th>四</th>";
echo "<th>五</th>";
echo "<th style='color:#ff0000;'>六</th>";
echo "</tr>";
//4.遍历输出日历
$dayindex=1;
while($dayindex<=$daynum){
echo"<tr onmouseOver='overTr(this)'onmouseOut='outTr(this)'>";
for($i=1;$i<=7;$i++){//循环输出7天信息
if($dayindex<=$daynum&&($w<$i||$dayindex!=1)){
//'2014-10-1'(传入这样一个字符串)$year-$month-$d
if($dayindex==$day){
echo "<th style='background:#ff0000;'><a href='?y={$year}&m={$mon}&d={$dayindex}'>{$dayindex}</a></th>";
}else{
echo "<th onmouseOver='overTh(this)' onmouseOut='outTh(this)'><a href='?y={$year}&m={$mon}&d={$dayindex}'>{$dayindex}</a></th>";
}
$dayindex++;
}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='calendar.php?y={$prey}&m={$mon}&d={$day}'><<</a> ";
echo "<font face='隶书'color='#663399'>{$year}年</font> ";
echo "<a href='calendar.php?y={$nexty}&m={$mon}&d={$day}'>>></a> ";
echo" ";
echo"<a href='calendar.php?y={$year}&m={$prem}&d={$day}'><</a> ";
echo "{$mon}月";
echo "
echo "</td></tr>";
echo "<tr onmouseOver= 'overTr(this)'onmouseOut='outTr(this)'>
echo "
echo "</td></tr>";
echo "</table>";
echo "</div>";
?>
<script>
var oriCol=null;
function overTr(obj){
oriCol=obj.bgColor;
obj.bgColor='#0f0';
}
function outTr(obj){
obj.bgColor =oriCol;
}
function overTh(obj) {
oriCol=obj.bgColor;
obj.bgColor='red';
}
function outTh(obj){
obj.bgColor=oriCol ;
}