急高分,JS不太会帮助看看我这个PHP日历应该怎么改?

appgg 2007-01-17 01:44:12
我想点击这个日历中的一天,则那一天背景色不同,帮助看看该怎么改?

function calendar()
{
if($_GET['ym'])
{
$year = substr($_GET['ym'],0,4);
$month = substr($_GET['ym'],4,(strlen($_GET['ym'])-4));

if($month>12)
{
$year += floor($month/12);
$month = $month % 12;
}
if($year > 2030) $year = 2030;
if($year < 1980) $year = 1980;
}

$year = isset($year) ? $year : date('Y');
$month = isset($month) ? $month : date('n');

if($year==date('Y') && $month==date('n'))
{
$today = date('j');
}


if($month-1 == 0)
$prevmonth = ($year - 1)."12";
else $prevmonth = $year.($month - 1);

if($month+1 == 13)
$nextmonth = ($year+1)."1";
else $nextmonth = $year.($month+1);

$prevyear = ($year - 1).$month;
$nextyear = ($year + 1).$month;

echo '
<table width="160" border="0" cellpadding="2" cellspacing="2" >
<tr> ';
echo ' <td class="weekday" width="15%" ><a href="?ym='.$prevyear.'"><<</a></td> ';
echo ' <td class="normalday" width="15%" ><a href="?ym='.$prevmonth.'"><</a></td> ';
echo ' <td colspan="3" class="normalday">'.getmonth($month).','. $year.'</td> ';
echo ' <td class="normalday" width="15%" ><a href="?ym='.$nextmonth.'">></a></td>';
echo ' <td class="weekday" width="15%" ><a href="?ym='.$nextyear.'">>></a></td> ';
echo ' </tr>
<tr>
<td width="27" class="weekday">Sun</td>
<td width="27" class="normalday">Mon</td>
<td width="27" class="normalday">Tue</td>
<td width="27" class="normalday">Wed</td>
<td width="27" class="normalday">Thu</td>
<td width="27" class="normalday">Fri</td>
<td width="27" class="weekday">Sat</td>
</tr> ';
$nowtime = mktime(0,0,0,$month,1,$year);//当月1号转为秒
$daysofmonth = date(t,$nowtime);//当月天数
$weekofbeginday = date(w,$nowtime);//当月第一天是星期几
$weekofendday = date(w,mktime(0,0,0,$month+1,0,$year));//当月最后一天是星期几
$daysofprevmonth = date(t,mktime(0,0,0,$month,0,$year));//上个月天数

$count = 1;//计数
//列出上月后几天
for($i = 1 ; $i <= $weekofbeginday ; $i++)
{
echo "<td class='othermonth'>".($daysofprevmonth-$weekofbeginday+$i)."</td>";
$count++;
}
//当月全部
for($i = 1 ; $i <= $daysofmonth ; $i++)
{
$css = ($count%7==0 || $count%7==1)?"weekday":"normalday";
if($i == $today)
{
$css .= "today";
}

echo "<td class='".$css."'><a href='dl.php?ym=".$year.$month."&dd=".$i."&date=".$i."&month=".$month."&year=".$year."' >".$i."</a></td>";
if($count%7==0) echo "</tr><tr>";
$count++;
}
//下月前几天
for ($i = 1;$i <= 6-$weekofendday;$i++)
{
echo "<td class='othermonth'>".$i."</td>";
}

echo '
<tr>
<td colspan="7"></td>
</tr>
</table> ';
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>calendar</title>
<style type="text/css">
<!--
.weekday {
font-size: 9pt;
color: #FF0000;
text-align: center;
}
.normalday {
font-size: 9pt;
color: #000000;
text-align: center;
}
.weekdaytoday {
font-size: 9pt;
color: #FF0000;
text-align: center;
background-color: #FFD9D9;
font-weight: bold;
}
.normaldaytoday {
font-size: 9pt;
color: #000000;
text-align: center;
background-color: #000000; ===
font-weight: bold;
}
.othermonth {
font-size: 9pt;
font-style: italic;
color: #999999;
text-align: center;
}
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #DADADA;
}
.body,td{
font-family:"Arial";
font-size:8pt;
color:#000000;
}
.TrOut{
background:#dddddd;
height:26;
border:1 solid #999999;
border-top-color:#f4f4f4;
border-left-color:#f4f4f4;
}
.TdOver{
background:#eeeeee;
height:20;
border:1 solid #ffffff;
border-top-color:#9c9c9c;
border-left-color:#9c9c9c;
}
.TdOut{
background:#eeeeee;
height:20;
border:1 solid #9c9c9c;
border-top-color:#ffffff;
border-left-color:#ffffff;
}
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #DADADA;
}
-->
</style>
</head>

<body>
<?php
calendar();


?>
...全文
288 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
foolbirdflyfirst 2007-01-19
  • 打赏
  • 举报
回复
...
var today = cur.getDate();
foolbirdflyfirst 2007-01-19
  • 打赏
  • 举报
回复
sorry~输写有误
======
var cur = new Date();
var today = $cur.getDate();
if(document.getElementById(today ).className == "normaldaytoday")
{
document.getElementById(today).className = "normalday";
document.getElementById(i).className = "normaldaytoday";
}
foolbirdflyfirst 2007-01-19
  • 打赏
  • 举报
回复
......
写个简单的onclick事件
<script language="javascript">
function changebg(i)
{
$cur = new Date();
$today = $cur.getDate();
if(document.getElementById($today).className == "normaldaytoday")
{
document.getElementById($today).className = "normalday";
document.getElementById(i).className = "normaldaytoday";
}
else
{
var j;
for(j=1;j<=31;j++)
{
if(document.getElementById(j).className == "normaldaytoday")
{
if(i != j)
{
document.getElementById(j).className = "normalday";
document.getElementById(i).className = "normaldaytoday";
}
}
}

}
}
</script>
然后表格增添一个id
echo "<td id='{$i}' onClick=\"changebg(this.id)\" class='".$css."'><a href='#?ym=".$year.$month."&dd=".$i."&date=".$i."&month=".$month."&year=".$year."' >".$i."</a></td>";这是舍弃链接的情况,具体情况自己参考着改吧
appgg 2007-01-19
  • 打赏
  • 举报
回复
我就是想实现上面的效果
appgg 2007-01-19
  • 打赏
  • 举报
回复
可能要用PHP判断,
像这样:原来是19号的:
http://www.skyname.cn/01.jpg
点了18号就是这样的了:
http://www.skyname.cn/02.jpg
foolbirdflyfirst 2007-01-19
  • 打赏
  • 举报
回复
"<td onmouseover=\"this.className='TdOver'\" onmouseout=\"this.className='{$css}'\" class='".$css."'><a href='dl.php?ym=".$year.$month."&dd=".$i."&date=".$i."&month=".$month."&year=".$year."' >".$i."</a></td>";
你点击之后就跳到dl.php这个页面去啦,就触发链接啦。这个链接你还要不要。
appgg 2007-01-19
  • 打赏
  • 举报
回复
我的意思是,点击后,那阴影就在那天,比如今天是19号,我点了11号,那背景色就是在11号上面。
foolbirdflyfirst 2007-01-19
  • 打赏
  • 举报
回复
点击不就触发链接了吗,你想怎么改?
appgg 2007-01-19
  • 打赏
  • 举报
回复
foolbirdflyfirst()
你误会我的意思了,我想实现是点击后,那阴影就在那天上,而不是鼠标经过

再顶!两天了,等会加分!
cnhussein 2007-01-18
  • 打赏
  • 举报
回复
mark,JF.
appgg 2007-01-17
  • 打赏
  • 举报
回复
多谢楼上的,我试试
foolbirdflyfirst 2007-01-17
  • 打赏
  • 举报
回复
无非加个鼠标事件。
//当月全部
for($i = 1 ; $i <= $daysofmonth ; $i++)
{
$css = ($count%7==0 || $count%7==1)?"weekday":"normalday";
if($i == $today)
{
$css .= "today";
}

echo "<td onmouseover=\"this.className='TdOver'\" onmouseout=\"this.className='{$css}'\" class='".$css."'><a href='dl.php?ym=".$year.$month."&dd=".$i."&date=".$i."&month=".$month."&year=".$year."' >".$i."</a></td>";
if($count%7==0) echo "</tr><tr>";
$count++;
}
visam168 2007-01-17
  • 打赏
  • 举报
回复
强的一笔....

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧