单击按钮后,如何为未来几天添加元素?

时间:2018-09-24 16:51:59

标签: php

为什么下面的内容在单击nextday之后没有读nextbutton类?

我的prevnext按钮代码:

/prevbutton
$prev = date('Y-m', mktime(0, 0, 0, date('m', $timestamp)-1, 1, date('Y', $timestamp)));
//next button
$next = date('Y-m', mktime(0, 0, 0, date('m', $timestamp)+1, 1, date('Y', $timestamp)));

这是我的日历代码:

$day_count = date('t', $timestamp);

// 0:Sun to 6:SAT
$str = date('w', mktime(0, 0, 0, date('m', $timestamp), 1, date('Y', $timestamp)));

$weeks = array();
$week = '';
$prevdays = true;
//Add empty cell
$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; //CSS color:green
        $prevdays = false;
    } 
    else if ($prevdays)
    {
        //prevdays
         $week .= '<td class="prevday">'.$day; //CSS color:gray
    }
    else
    {
        //generate nextday
        $week .= '<td class="nextday">'. $day; //CSS bordered green
    }
        //close table of weeks
        $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 = '';
    }
}

在第一张图片中,2018年9月的读取代码运行良好,但在2018年10月,它显示了之前的所有日期。

这是我的输出:

enter image description here

0 个答案:

没有答案