改变当天的背景颜色php css

时间:2016-02-07 14:41:30

标签: php html css

here is the screenshoot of my result 我试图使一个压缩机有一些问题的代码。错误是generatring的代码是tablerow.php根据我我已经把评论放在我认为错误是。 我正在尝试更改当前的背景颜色,但不是更改特定单元格的颜色,而是整个月的背景颜色已更改,因此对于整月2月,颜色为绿色。

calander.php

<html>
<?php include 'dbconnect.php' ?>

<head>Event Calander</head>
<body>
<script>
        function goLastMonth(month, year){
            if(month == 1) {
                --year;
                month = 13;
            }
            document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+(month-1)+"&year="+year;

        }
        function goNextMonth(month, year){
            if(month == 12) {
                ++year;
                month = 0;
            }
            document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+(month+1)+"&year="+year;

        }
</script>
<style>
        .today{
            background-color: #00ff00;
        }
        .event{
            background-color: #FF8080;
        }
</style>

<table border='0'>
<tr>

    <td width='50px' colspan='7' align="center">
    <?php include 'tableheader.php' ?>
    <?php include 'addingData.php' ?>
    <?php echo $monthName.", ".$year; ?></td>
</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 include 'tablerow.php' ?>

</table>
<table >
        <tr>
            <td ><input style='width:50px;' type='button' value='<'name='previousbutton' onclick ="goLastMonth(<?php echo $month.",".$year?>)"></td>
            <td width='50px'></td>
            <td width='50px'></td>
            <td width='50px'></td>
            <td width='50px'></td>
            <td width='50px'></td>
            <td width='50px'><input style='width:50px;' type='button' value='>'name='nextbutton' onclick ="goNextMonth(<?php echo $month.",".$year?>)"></td>
        </tr>
</table>
<?php include 'schedule.php' ?>
</body>
</html>

tablerow.php(这是我改变当天颜色的地方)

   
<?php
        echo "<tr>";

        $first_day = mktime(0,0,0,$month, 1, $year) ;
        $name_of_day = date('w', $first_day) ; //get the day of the weeek
        //caluting blank days for the month for diaplay 
        switch($name_of_day){   
            case "0": $blank = 0; 
            break;   
            case "1": $blank = 1; 
            break;   
            case "2": $blank = 2; 
            break;   
            case "3": $blank = 3; 
            break;   
            case "4": $blank = 4; 
            break;   
            case "5": $blank = 5; 
            break;   
            case "6": $blank = 6; 
            break;   
        }

        $total_days = cal_days_in_month(0, $month, $year) ;  
        $day_count = 1; 
        while ( $blank > 0 )   {   
            echo "<td></td>";   
            $blank = $blank-1;   
            $day_count++;  
        }
        $day_num = 1;
        while ( $day_num <= $total_days )   
        {  
            $todaysDate = date("n/j/Y");
            $dateToCompare = $month. '/' . $day. '/' . $year;
            echo "<td align='center' ";
            //this is where i am comparing two dates but it is giving error
            //every day of the current month is turnin green
            if ($todaysDate == $dateToCompare)
            {
                echo "class ='today'";

            }  
            echo "> <a href='".$_SERVER['PHP_SELF']."?month=".$month."&day=".$day_num."&year=".$year."&v=true'>".$day_num."</a></td>";

            $day_num++;   
            $day_count++;    
            //Make sure we start a new row every week  
            if ($day_count > 7)  
            {  
                echo "</tr><tr>";  
                $day_count = 1;  
            }  
        }
        while ( $day_count >1 && $day_count <=7 )   
            {   
                echo "<td> </td>";   
                $day_count++;   
            }  


            echo "</tr>"


?>

1 个答案:

答案 0 :(得分:1)

尝试更改此内容:

  $(document).ready(function(){  
     $('button').click(function(){
        $('#externDiv').load('external.html');

       });  

     });

进入这个:

$dateToCompare = $month. '/' . $day. '/' . $year;