Javascript 突出显示表格日期时出错

Javascript 突出显示表格日期时出错,javascript,php,css,Javascript,Php,Css,这个代码有什么问题?我想强调从现在开始的所有日子+2周。但它们都会在.highlight类中突出显示。错误在哪里 <?php // get two weeks from now $date_in_two_weeks = strtotime('+2 weeks'); $date_in_two_weeks = date("Y-m-d",$date_in_two_weeks); // get the date to compare, from db or whatever you want

这个代码有什么问题?我想强调从现在开始的所有日子+2周。但它们都会在.highlight类中突出显示。错误在哪里

<?php 
// get two weeks from now
$date_in_two_weeks = strtotime('+2 weeks');
$date_in_two_weeks = date("Y-m-d",$date_in_two_weeks);

// get the date to compare, from db or whatever you want
$date_to_compare = "2014-02-01";

// compare the date in your list to now + 2 weeks and then put the date difference into $days_difference
$date_from_list = new DateTime($date_to_compare);
$date_in_two_weeks = new DateTime($date_in_two_weeks);
$days_difference = $date_from_list->diff($date_in_two_weeks);

if ($days_difference->days > 14) {
    $highlight_css_class = "highlight";
} else {
    $highlight_css_class = "none";
}
?>
<style>
.highlight { 
    color:#cc0000;
}
.none { 
}
</style>
<fieldset>
<table class="tablesorter" id="my-table" border="1" style="border-collapse:collapse">
        <thead>
            <tr>
                <th>REK</th>
                <th>BESCHRIJVING</th>
                <th>VERVALDATUM</th>
            </tr>
        </thead>
        <tbody>


<tr><td>A1</td><td>hamburger</td><td class="<?php echo $highlight_css_class;?>">2014-02-10</td></tr>

<tr><td>A1</td><td>tomato</td><td class="<?php echo $highlight_css_class;?>">2014-06-10</td></tr>


        </tbody>
    </table>

.突出显示{
颜色:#cc0000;
}
.none{
}
雷克
贝什里金
维瓦尔达姆
一个汉堡包试试这个

$date两周=标准时间(“+2周”)

而不是

$date两周=标准时间(“+2周”)


要获得下两周的正确时间戳,您必须输入
,而不是
。您没有对每个日期进行任何比较,而是只进行一次比较。创建一个函数,并传入当前日期以确定突出显示类,或者您可以在jquery中简单地执行此操作。您总是比较“2014-02-01”,您想要比较的日期“2014-02-10”和“2014-06-10”在您的代码中从未进行过比较。我在我编写的代码中找不到错误。。。你能给我一个工作的例子吗?在不给类的情况下检查代码是否工作良好。添加类可能有问题。现在你自己问题的四个副本中的一个请立即停止。因为差异大于14。尝试将比较日期更改为2014-02-15