gpt4 book ai didi

JavaScript 日历无法正常工作

转载 作者:行者123 更新时间:2023-12-03 07:51:23 24 4
gpt4 key购买 nike

我正在尝试根据 youtube 的视频教程使用 php 制作日历。我正在做他们所做的事情,但与他们的表有所不同。我找不到我的错误......请任何机构帮助......给出代码和图片......

这是我的日历-

calender

这是教程日历-

calender

<html>
<head>
<title>Calender</title>
</head>

<body>
<?php
if(isset($_GET['day']))
{
$day = $_GET['day'];
}else
{
$day = date("j");
}

if(isset($_GET['month']))
{
$month = $_GET['month'];
}else{
$month = date("n");
}

if(isset($_GET['year']))
{
$year = $_GET['year'];
}else{
$year = date("Y");
}

//calender variable-----------
$currentTimeStamp = strtotime($year-$month-$day);
$monthName = date("F",$currentTimeStamp);
$numDays = date("t",$currentTimeStamp);
$counter = 0;
?>


<table border = "1">
<tr>
<th><input style = "width : 50px"type = "button" value = "<" name = "prevbutton"></input></th>
<th colspan = "5"><?php echo $monthName.", ".$year?></th>
<th><input style = "width : 50px" type = "button" value = ">" name = "nextbutton"></input></th>
</tr>

<tr>
<td width = "50px">Sun</td>
<td width = "50px">Mon</td>
<td width = "50px">Tue</td>
<td width = "50px">Wed</td>
<td width = "50px">Thu</td>
<td width = "50px">Fri</td>
<td width = "50px">Sat</td>
</tr>

<?php
echo "<tr>";
for($i = 1;$i<$numDays+1;$i++,$counter++)
{
$timeStamp = strtotime($year-$month-$i);
if($i == 1)
{
$firstDay = date('w', $timeStamp);
for($j = 0;$j<$firstDay;$j++,$counter++)
{
echo "<td>&nbsp</td>";
}
}
if($counter%7==0)
{
echo "</tr><tr>";
}
}
echo "</tr>";
?>

</table>
</body>

最佳答案

您的 php 代码中有 3 个错误

  echo "<tr>";
for($i = 1;$i<$numDays+1;$i++,$counter++)
{
$timeStamp = strtotime($year.'-'.$month.'-'.$i);// it should be string
if($i == 1)
{
$firstDay = date('w', $timeStamp);
for($j = 0;$j<$firstDay;$j++,$counter++)
{
echo "<td>&nbsp</td>"; // show days
}
$counter++; // first row counter correction
}

echo "<td>$i</td>";

if($counter%7==0)
{
echo "</tr><tr>";
}
}
echo "</tr>";

关于JavaScript 日历无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34976694/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com