如果当前日期是今天,我在网上找不到有关添加课程的正确答案。
我有一个事件列表,如果今天匹配,我想在事件日期中添加课程。
输出
12 13 September 2018 Thursday Workout
2 22 September 2018 Saturday Workout <-- today
1 25 September 2018 Tuesday Meeting
3 06 October 2018 Saturday Meeting
13 11 October 2018 Thursday Meeting
4 22 October 2018 Monday Workout
7 27 October 2018 Saturday Meeting
5 05 November 2018 Monday Workout
14 07 November 2018 Wednesday Meeting
HTML
<table class="calendar">
<thead>
<th>#</th>
<th>Date</th>
<th>Day</th>
<th>Item</th>
</thead>
<?php while($row = mysqli_fetch_assoc($result)) :
$cId = $row['c_id'];
$cDate = $row['c_datetime'];
$ciName = $row['ci_name'];
$ccName = $row['cc_name'];
?>
<tr>
<td><?php echo $cId; ?></td>
<td class="day"><?php echo dateFormatFullMonth($cDate); ?></td>
<td><?php echo dateFormatDay($cDate); ?></td>
<td><?php echo $ciName; ?></td>
</tr>
<?php endwhile; ?>
</table>
下面的这个与日期匹配。
$('table.calendar tr td.day').eq(new Date().getDay()).parent().addClass('bg-success');
答案 0 :(得分:0)
所以我在这里找到了答案。
https://stackoverflow.com/a/33935926/5413283
<!-- Today is 25 Sep 18 -->
<div id="datecontainer">
<p data-date="2018-9-20">2018-09-20</p>
<p data-date="2018-9-21">2018-09-21</p>
<p data-date="2018-9-22">2018-09-22</p>
<p data-date="2018-9-23">2018-09-23</p>
<p data-date="2018-9-24">2018-09-24</p>
<p data-date="2018-9-25">2018-09-25</p> <!-- this will have the class -->
</div>
$(function() {
var d =new Date();
var curmonth = d.getMonth()+1;
var curDate = d.getFullYear() + "-" + curmonth + "-" +d.getDate();
$("#datecontainer p[data-date="+curDate+"]").addClass("today");
});
还有两个月的数字
var curDate = d.getFullYear() + "-0" + curmonth + "-" +d.getDate();