我正试图在我的身体中添加一个新的类,但仅限于愚人节。我不能让它工作,因为我几乎没有使用Javascript的经验。下面是我的代码:
if (new Date().getMonth() == 4 && getDate == 1) {
document.body.classList.add("pils");
}
为了使其正常工作,我需要更改哪些内容?
发布于 2019-12-18 21:24:33
getMonth()方法根据本地时间以从零开始的值返回指定日期中的月份(其中零表示一年中的第一个月)。
// Month will be 3, because started from 0
if (new Date().getMonth() == 3 && new Date().getDate() == 1) {
document.body.classList.add("pils");
}
//use reusable date object
var mydate = new Date();
if (mydate.getMonth() == 3 && mydate.getDate() == 1) {
document.body.classList.add("pils-new");
}
https://stackoverflow.com/questions/59392202
复制相似问题