我是 PHP 和 javascript 编程的新手。我有一个使用 PHP 回显的链接。
<?php .....echo "<td><font class='calendar'><a onclick='showevent($currentday)' href='#'>". $currentday. "</a></font></td>"; ....?>
我需要从上面的链接调用函数 showevent()。
<script>
function showevent($day){
$thisday = $day;
document.showevent.submit();
}
</script>
该函数将提交如下表格:
<form action="./event.php" name="showevent" method="post">
<input type="hidden" name="page" value="showevent" />
<input type="hidden" name="month" value="<?php echo $cMonth;?>" />
<input type="hidden" name="year" value="<?php echo $cYear; ?>" />
<input type="hidden" name="day" value="<?php echo $thisday; ?>" />
</form>
javascript函数不起作用。任何人都可以帮助建议和指导我吗?
完整的html代码:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="./css/mystyle.css">
<script>
function showevent($day){
$thisday = $day;
document.showevent.submit();
}</script>
</head>
<body>
<p class="menutitle">Event Calendar</p>
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])){
$_REQUEST["month"] = date("n");
}
if (!isset($_REQUEST["year"])) {
$_REQUEST["year"] = date("Y");
}
$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;
}
?>
<table class="calendar">
<tr align="center">
<td class="calendarTop">
<table class="calendarNav">
<tr>
<td class="calendarOption" onmouseover="this.className='calendarOptionHover'" onmouseout="this.className='calendarOption'" align="center"><a href="#" onclick="document.forms.prev.submit()">Previous</a>
</td>
<td width="60%"><p class="subtitle"><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></p></td>
<td class="calendarOption" onmouseover="this.className='calendarOptionHover'" onmouseout="this.className='calendarOption'" align="center"><a href="#" onclick="document.forms.next.submit()">Next</a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td >
<table class="calendarTop">
<tr>
<td class="calendarTitle" ><font>S</font>
</td>
<td class="calendarTitle" ><font>M</font>
</td>
<td class="calendarTitle" ><font>T</font>
</td>
<td class="calendarTitle" ><font>W</font>
</td>
<td class="calendarTitle" ><font>T</font>
</td>
<td class="calendarTitle" ><font>F</font>
</td>
<td class="calendarTitle" ><font>S</font>
</td>
</tr>
<?php
require "./dbconnect.php";
$result = mysql_query(" SELECT * FROM event WHERE month = $cMonth AND year=$cYear ORDER BY date"); //---->resource
$before =0;
$after =99;
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
// $cMonth; ---> month name
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
$eventday = Array(31);
for ($k =0; $k<32; $k++){
$eventday[$k]=false;
}
while ($row = mysql_fetch_array($result)){
$eventday[$row['date']]=true;
}
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ) {
echo "<tr>";
}
if($i < $startday) {
echo "<td></td>";
}else{
$currentday = ($i - $startday + 1);
if($eventday[$currentday] == true){
echo "<td class='eventtrue'><font class='calendar'><a onclick='javascript: showevent($currentday);' href='#'>". $currentday. "</a></font></td>";
}else{
echo "<td class='eventfalse'><font class='calendar'>". ($i - $startday + 1). "</font></td>";
}
}//--2 brackets
if(($i % 7) == 6 ) {
echo "</tr>";
}
}
?>
</table>
<tr>
<td><form action="./event.php" name="prev" method="post">
<input type="hidden" name="page" value="calendar" /> <input
type="hidden" name="month" value="<?php echo $prev_month;?>" /> <input
type="hidden" name="year" value="<?php echo $prev_year; ?>" />
</form>
<form action="./event.php" name="next" method="post">
<input type="hidden" name="page" value="calendar" /> <input
type="hidden" name="month" value="<?php echo $next_month;?>" /> <input
type="hidden" name="year" value="<?php echo $next_year; ?>" />
</form>
<form action="./event.php" name="showevent" method="post">
<input type="hidden" name="page" value="showevent" />
<input type="hidden" name="month" value="<?php echo $cMonth;?>" />
<input type="hidden" name="year" value="<?php echo $cYear; ?>" />
<input type="hidden" name="day" value="<?php echo $thisday; ?>" />
</form></td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</body>
</html>