我不知道这是否可行,但我想根据PHP中的某一天将某个类应用于某个类。代码就是这样的。它用于显示页面上的开放时间段内的哪一天。
<?php
$dayoftheweek=cal_to_jd(CAL_GREGORIAN,date("m"),date("d"),date("Y"));
$whatdayisit=(jddayofweek($dayoftheweek,1));
if ($whatdayisit === Monday){
// SET #monday to class open_colour
}
else if ($whatdayisit === Tuesday) {
// SET #tuesday to class open_colour
}
//.........
?>
我不确定PHP是否可以这样做,或者JS / JQuery有更好的方法...
ADDITION ****
<?php
if ($whatdayisit === Monday){
echo
<div class="opening_times_day_orange">Monday</div> <div class="opening_times_times_orange">07:30 - 23:00 </div>
}
else {
echo
<div class="opening_times_day">Monday</div> <div class="opening_times_times">07:30 - 23:00 </div>
}
?>
答案 0 :(得分:1)
我不完全理解为什么你需要这个,但是不会有一个简单的JS解决方案(如果你需要它在前端):
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
break;
}
然后使用jquery:http://www.w3schools.com/jquery/html_addclass.asp
将day的值添加到您需要的任何内容中