使用javascript按月自动更改图片

使用javascript按月自动更改图片,javascript,php,html,css,Javascript,Php,Html,Css,我不知道这是不是问这个问题的合适地方 嗯,我想使用一个脚本,它会自动更改我的网站的开始网站的图片。因此,脚本应该检查月份,如果月份是三月,则使用picture1.jpg,如果月份是八月,则使用picture2.jpg 是否可以这样做,例如使用javascript 我期待着你的回答,如果你能帮我创作这样一个剧本,我会很高兴的 谢谢大家! 这是一个示例,可以通过以下代码进行修改: <img id="Logo" src="Images/default.png" alt="KnowledgeBas

我不知道这是不是问这个问题的合适地方

嗯,我想使用一个脚本,它会自动更改我的网站的开始网站的图片。因此,脚本应该检查月份,如果月份是三月,则使用picture1.jpg,如果月份是八月,则使用picture2.jpg

是否可以这样做,例如使用javascript

我期待着你的回答,如果你能帮我创作这样一个剧本,我会很高兴的


谢谢大家!

这是一个示例,可以通过以下代码进行修改:

<img id="Logo" src="Images/default.png" alt="KnowledgeBase" width="75%" onload="logo(this)" />


    function logo(img) {
      if (img.src.indexOf('default')==-1) return; // already changed 
      var d = new Date();
      var Today = d.getDate();
      var Month = d.getMonth();
      var src;
      if (Month === 10 && (Today >= 23 && Today <= 26)) {
        src = "Images/doodles/blah1.png";
      } else if (Month === 11 && (Today >= 23 && Today <= 26)) {
        src = "Images/doodles/blah2.png";
      } else if ((Month === 11 && Today >= 30) || (Month === 0 && Today <= 2)) {
        src = "Images/doodles/blah3.png";
      } else if (Month === 6 && (Today >= 3 && Today <= 5)) {
        src = "Images/doodles/blah4.png";
      } 
      img.src=src;
    }

功能标识(img){
if(img.src.indexOf('default')=-1)返回;//已更改
var d=新日期();
var Today=d.getDate();
var Month=d.getMonth();
var-src;

如果(Month==10&&(Today>=23&&Today=23&&Today=30)| |(Month==0&&Today=3&&Today=6&&total=9&&total=2&&total=2&&total)不是一项代码编写服务,那么在SO或google上搜索会更合适。我知道这一点。但我希望我能在这里得到我需要的帮助。第一部分是什么日期?
<script language="javascript" type="text/javascript"> 
var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); 
var thetime = new Date(); 
var themonth = thetime.getMonth(); 
document.write('<img src="image' + months[themonth] + '.gif" alt="Image of the month: ' + months[themonth] + '" />'); 
</script>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="banner-container" style="width:400px;height:300px;"></div>

<script>
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var total = month;

// Summer
if (total >= 6 && total <= 8)
{
    document.getElementById("banner-container").style.backgroundImage = "url('images/winter.png')";
}
// Autumn
else if (total >= 9 && total <= 11)
{
    document.getElementById("banner-container").style.backgroundImage="url('images/fall.png')";
}
// Winter
else if (total == 12 || total == 1 || total == 2)
{
    document.getElementById("banner-container").style.backgroundImage = "url('images/winter.png')";
}
// Spring
else if (total >= 2 && total <= 6)
{
    document.getElementById("banner-container").style.backgroundImage = "url('images/spring.png')";
}
else
{
    document.getElementById("banner-container").style.backgroundImage = "url('images/summer.png')";
}
</script>

</body> </html>