這個外掛程式我試驗了下,發現問題如下:
①在年月跳轉的時候程式碼有個<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" " ;
echo "{$mon}月 ";
echo "
echo " td>";
echo "";
#echo "";
?>
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" " ;
echo "{$mon}月 ";
echo "
echo " td>";
echo "
echo "
echo "
echo "";
#echo "";
?>
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;
##}