每月更换一张图片

  • 本文关键字:一张 javascript html
  • 更新时间 :
  • 英文 :


我想在一个月内出现一个特定的标志。我尝试了以下方法,但从来没有成功过。一个是gif格式,另一个是PNG格式。

Javascript:

var logo = document.getElementById("logo");
const refreshStatus = () => {
// Get dates/time/hours
let today = new Date(); //today date
//Show available if this matches
if (today.getMonth == 5) {
logo.src='../../img/logo2.gif';
} else {
logo.src='../../img/logo.png';
}
}
// run when starting
refreshStatus();
// updates every 8 seconds
setInterval(refreshStatus, 8000);

HTML:

<a href="../index.html" class="index-link"><img src="../img/logo.png" alt="Logo" class="logo" id="logo"></a>
<script src="js/pride.js"></script>

您需要调用getMonth,因为它是一个函数(或者更具体地说是Date.prototype上的一个方法)。当前你正在比较一个函数和一个数字,这永远不会为真。

if (today.getMonth() == 5) { // ...

相关内容

最新更新