Php 行作为链接可单击

Php 行作为链接可单击,php,html,css,Php,Html,Css,我用PHP制作了一个日历,现在我想让可以作为链接点击,而不是像现在这样在日历中添加文本 else echo "<td align='center' valign='middle' height='20px' style='background-color:gray;'> <a href='days.php?day=". ($i - $star

我用PHP制作了一个日历,现在我想让
可以作为链接点击,而不是像现在这样在日历中添加文本

else echo "<td align='center' 
               valign='middle' 
               height='20px' 
               style='background-color:gray;'>

                    <a href='days.php?day=". ($i - $startday + 1) . "&month=$cMonth&year=$cYear'>".
                         ($i - $startday + 1).
                    "</a>
           </td>";
else-echo”
";
类似这样的工作原理:

<td onclick="document.location = 'link.php';">&nbsp;</td>

但我不能让它在日历上工作

以下是网站上的所有代码:

<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",         "August", "September", "October", "November", "December");
?>
<?php
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
?>
<?php
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<!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=utf-8" />
<title>Timesedler</title>
<link href="Connections/small-device.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" class="index_logind">
<tr>
<td colspan="5" align="center"><strong><a href="home.php">T i m e s e d l e r</a>    </strong></td>
</tr>
<tr >
<td width="50%" colspan="2" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = 'tfbruger.php';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">Tilføj Bruger</td>
<td width="50%" colspan="2" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = 'sebrugere.php';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">Se Brugere</td>
</tr>
<tr>
<td width="50%" colspan="2" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = 'tftimer.php';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">Tilføj Timer</td>
<td width="50%" colspan="2" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = 'setimer.php';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">Se Timer</td>
</tr>
<tr>
<td width="50%" colspan="2" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = 'tfordre.php';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">Tilføj Ordre</td>
<td width="50%" colspan="2" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = 'seordre.php';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">Se Ordre</td>
</tr>
<tr>
<td width="40%" align="center" nowrap="nowrap">&nbsp;</td>
<td width="10%" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = '<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">&lt;</td>
<td width="10%" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = '<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">&gt;</td>
<td width="40%" align="center" nowrap="nowrap">&nbsp;</td>
</tr>
</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="2" class="index_logind">
<tr align="center">
<td colspan="7" bgcolor="#999999"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<td align="center" bgcolor="#999999"><strong>M</strong></td>
<td align="center" bgcolor="#999999"><strong>T</strong></td>
<td align="center" bgcolor="#999999"><strong>O</strong></td>
<td align="center" bgcolor="#999999"><strong>T</strong></td>
<td align="center" bgcolor="#999999"><strong>F</strong></td>
<td align="center" bgcolor="#999999"><strong>L</strong></td>
<td align="center" bgcolor="#999999"><strong>S</strong></td>
</tr>
<?php 
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday']-1;
$today = date("d");
for ($i=0; $i<($maxday+$startday); $i++) {
     if(($i % 7) == 0 ) echo "<tr>";
     if($i < $startday) echo "<td style='background-color:gray;'></td>";

else if(($i - $startday +1 ==$today) and ($cMonth == date("n")) and ($cYear == date("Y"))) echo "<td align='center' valign='middle' height='20px' style='background-color:#00FF00;'><a href='timer.php?day=". ($i - $startday + 1) . "&month=$cMonth&year=$cYear'>".($i - $startday + 1)."</a></td>";
else echo "<td align='center' valign='middle' height='20px' style='background-color:gray;'><a href='timer.php?day=". ($i - $startday + 1) . "&month=$cMonth&year=$cYear'>".($i - $startday + 1)."</a></td>";

if(($i % 7) == 6 ) echo "</tr>";
}
?>  
</table>
</body>
</html>

时间采集器

蒂尔夫·布鲁格
斯布鲁吉尔酒店
蒂尔夫øj定时器
Se定时器
蒂尔夫·奥德雷
秩序

M
T
O
T
F
L
S

使用一些JavaScript对代码进行一些小的更改

<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
?>
<?php
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
?>
<?php
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<!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=utf-8" />
<title>Timesedler</title>
<link href="Connections/small-device.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
    color: #FFF;
    text-decoration: none;
}
a:visited {
    text-decoration: none;
    color: #FFF;
}
a:hover {
    text-decoration: none;
    color: #FFF;
}
a:active {
    text-decoration: none;
    color: #FFF;
}
-->
</style>

<script type="text/javascript">

function addRowHandlers() {
var table = document.getElementById('calander'),
    cells = table.getElementsByTagName('td');

for (var i=0,len=cells.length; i<len; i++){
    cells[i].onclick = function(){
        var cell = this.id;
        if (cell > '') {
        window.location = cell;
        }
        /* if you know it's going to be numeric:
        console.log(parseInt(this.innerHTML),10);
        */
    }
}
}
</script>

</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" class="index_logind">
<tr>
<td colspan="5" align="center"><strong><a href="home.php">T i m e s e d l e r</a>    </strong></td>
</tr>
<tr >
<td width="50%" colspan="2" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = 'tfbruger.php';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">Tilføj Bruger</td>
<td width="50%" colspan="2" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = 'sebrugere.php';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">Se Brugere</td>
</tr>
<tr>
<td width="50%" colspan="2" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = 'tftimer.php';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">Tilføj Timer</td>
<td width="50%" colspan="2" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = 'setimer.php';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">Se Timer</td>
</tr>
<tr>
<td width="50%" colspan="2" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = 'tfordre.php';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">Tilføj Ordre</td>
<td width="50%" colspan="2" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = 'seordre.php';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">Se Ordre</td>
</tr>
<tr>
<td width="40%" align="center" nowrap="nowrap">&nbsp;</td>
<td width="10%" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = '<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">&lt;</td>
<td width="10%" align="center" nowrap="nowrap" bgcolor="#EEEEEE" style="border:1px solid black;" onclick="document.location = '<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>';" onMouseover="this.bgColor='#CCCCCC'"onMouseout="this.bgColor='#EEEEEE'">&gt;</td>
<td width="40%" align="center" nowrap="nowrap">&nbsp;</td>
</tr>
</table>

<table id="calander" onclick="addRowHandlers(this.id)" width="200" border="0" align="center" cellpadding="0" cellspacing="2" class="index_logind">
<tr align="center">
<td colspan="7" bgcolor="#999999"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<td align="center" bgcolor="#999999"><strong style="color: #FFFF00">M</strong></td>
<td align="center" bgcolor="#999999"><strong style="color: #FFFF00">T</strong></td>
<td align="center" bgcolor="#999999"><strong style="color: #FFFF00">W</strong></td>
<td align="center" bgcolor="#999999"><strong style="color: #FFFF00">T</strong></td>
<td align="center" bgcolor="#999999"><strong style="color: #FFFF00">F</strong></td>
<td align="center" bgcolor="#999999"><strong style="color: #FFFF00">S</strong></td>
<td align="center" bgcolor="#999999"><strong style="color: #FFFF00">S</strong></td>
</tr>

<?php 
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday']-1;
$today = date("d");
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ) echo "<tr>";
if($i < $startday) echo "<td style='background-color:gray;'></td>";

else if(($i - $startday +1 ==$today) and ($cMonth == date("n")) and ($cYear == date("Y"))) echo "<td id='timer.php?day=".($i - $startday + 1)."&month=$cMonth&year=$cYear' align='center' valign='middle' height='20px' style='background-color:#00FF00;'>".($i - $startday + 1)."</td>";
else echo "<td id='timer.php?day=".($i - $startday + 1)."&month=$cMonth&year=$cYear' align='center' valign='middle' height='20px' style='background-color:gray;'>".($i - $startday + 1)."</td>";

if(($i % 7) == 6 ) echo "</tr>";
}
?> 

</table>
</body>
</html>

时间采集器
函数addRowHandlers(){
var table=document.getElementById('calander'),
cells=table.getElementsByTagName('td');
对于(变量i=0,len=cells.length;i“”){
window.location=单元格;
}
/*如果您知道它将是数字:
log(parseInt(this.innerHTML),10);
*/
}
}
}

蒂尔夫·布鲁格
斯布鲁吉尔酒店
蒂尔夫øj定时器
Se定时器
蒂尔夫·奥德雷
秩序

M
T
W
T
F
S
S

也请发布生成的HTML。我没有IDE所有这些变量都将输出什么。sry对于这个网站上的新im,我试图编辑文章,但我不能说,我确实已经好几年没有看到HTML附加样式表了。你应该认真研究CSS支持——它将为你节省大量的输入。如果你使用一些JavaScript?示例->还可以添加style='pointer:cursor;'要获得一个点击光标或一个问题,您是否有一些链接,我可以在其中阅读如何将其更改为使用重定向代码?我以前从未使用过JavaScript。@user2734016好的,我已经更新了它以进行重定向,请告诉我它是否工作!我认为这一点是错误的:id='timer.php?day=($i-$startday+1)&month=$cMonth&year=$cYear'它输出:tftimer.php?month=1&year=2014更好,但它只在周一工作,我明天再看,我必须在5小时内起床:)