drm30963 2015-03-30 12:25
浏览 17

PHP - 根据星期几在ID上设置类

I dont know if this is possible but I want to apply a class to something based on a day of the week in PHP. The code would something like this. It is being used to show which day it is within an opening times section on a page.

<?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
    }


    //.........


?>

I'm not sure if PHP is the way to do this or is there a better way with 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>  
                }

                ?>
  • 写回答

1条回答 默认 最新

  • dongxian1921 2015-03-30 12:41
    关注

    I don't fully understand why you would need this, but wouldn't a simple JS solution be any better (if you need it in the front-end anyway):

       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;
        }
    

    then add the value of day to whatever you need with jquery: http://www.w3schools.com/jquery/html_addclass.asp

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line