如何根据当天更改背景

How to change a background depending on the current day

我知道如何根据日期更改背景(比如 31 日变成万圣节照片,其余时间变成其他背景)P.S 我什么尝试不使用 JavaScript 因为我不喜欢使用 JavaScript.

您将需要一个服务器端函数来执行此操作。

例如

$date = date("d F"); 

if($date == "18 May"){ 
echo "style=\"background:rgba(0,0,0,1);\"" // don't forget to escape quotes and such 
}  

在您的评论中您说 javascript 可以,所以这里是 javascript。

这将为您完成:https://jsfiddle.net/4p18mxg9/5/

JAVASCRIPT

    function myFunction() {
    switch (new Date().getDay()) {
    case 0:
        day = "Sunday";
        document.body.style.backgroundImage = "url('http://lorempixel.com/400/200/sports/1/')";
        break;
    case 1:
        day = "Monday";
        document.body.style.backgroundImage = "url('http://lorempixel.com/400/200/sports/1/')";
        break;
    case 2:
        day = "Tuesday";
        document.body.style.backgroundImage = "url('http://lorempixel.com/400/200/sports/1/')";
        break;
    case 3:
        day = "Wednesday";
        document.body.style.backgroundImage = "url('http://lorempixel.com/400/200/sports/1/')";
        break;
    case 4:
        day = "Thursday";
        document.body.style.backgroundImage = "url('http://lorempixel.com/400/200/sports/1/')";
        break;
    case 5:
        day = "Friday";
        document.body.style.backgroundImage = "url('http://lorempixel.com/400/200/sports/1/')";
        break;
    case 6:
        day = "Saturday";
        document.body.style.backgroundImage = "url('http://lorempixel.com/400/200/sports/1/')";
        break;
}
 document.getElementById("demo").innerHTML = "Today is " + day;   


}