如何将元素添加到过去的日子和以后的日子(仅工作日)

时间:2018-09-18 12:06:54

标签: php ajax

我想将过去工作日的颜色更改为灰色 然后将颜色更改为蓝色

我的代码是:

$week .= str_repeat('<td></td>', $str);
for ( $day = 1; $day <= $day_count; $day++, $str++)
{
    $date = $ym . '-' . $day;

    if ($today == $date) 
    {
        $week .= '<td class="today">' . $day;
    } 
        else 
    {
        $week .= '<td>'.$day;
    }
        $week .= '</td>';


    // End of the week OR End of the month
    if ($str % 7 == 6 || $day == $day_count) {
        if ($day == $day_count) {
            // Add empty cell
            $week .= str_repeat('<td></td>', 6 - ($str % 7));
        }
        $weeks[] = '<tr>' . $week . '</tr>';
        // Prepare for new week
        $week = '';
    }
}

这是我的日历

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试一下:

$previous_days = true;
$week .= str_repeat('<td></td>', $str);
for ( $day = 1; $day <= $day_count; $day++, $str++)
{
    $date = $ym . '-' . $day;
    if ($today == $date) {
        $week .= '<td class="today">' . $day;
        $previous_days = false;
    }else if($previous_days){
        $week .= '<td class="previous-day">'.$day;
    }else{
        $week .= '<td class="upcoming-day">'.$day;
    }
        $week .= '</td>';

    // End of the week OR End of the month
    if ($str % 7 == 6 || $day == $day_count) {
        if ($day == $day_count) {
            // Add empty cell
            $week .= str_repeat('<td></td>', 6 - ($str % 7));
        }
        $weeks[] = '<tr>' . $week . '</tr>';
        // Prepare for new week
        $week = '';
    }
}