所以我对Javascript并不擅长,但我设法做了一些例子,然后将它们合并到一起:
var date = new Date().getDate();
var greeting;
if (date < 24) {
greeting = "Nej det är:";
} else {
greeting = "Ja!";
document.getElementById("clockdiv").style.visibility = "hidden";
}
document.getElementById("demo").innerHTML = greeting;
它应该在指定的日期显示一个问候语,如果它不是那个日期,它将显示一些其他的东西。
问题:
答案 0 :(得分:2)
据我所知,你是指这个月的某一天。
Js fiddle:https://jsfiddle.net/tscm02xb/
var dateObj = new Date();
var day = dateObj.getUTCDate();
var greeting;
if (day < 24) {
greeting = "Nej det är:";
} else {
greeting = "Ja!";
document.getElementById("clockdiv").style.visibility = "hidden";
}
document.getElementById("demo").innerHTML = greeting;
答案 1 :(得分:1)
Date().getDate()
仅返回该月的某一天。你可以试试这个。
var date = new Date();
var greeting;
if ( !(date.getDate === 24 && date.getMonth() === 11) ) {
greeting = "Nej det är:";
} else {
greeting = "Ja!";
document.getElementById("clockdiv").style.visibility = "hidden";
}
document.getElementById("demo").innerHTML = greeting;
答案 2 :(得分:1)
应该有所帮助:
var date = new Date();
var day = date.getDate();
var month = date.getMonth();
var greeting;
if (day !== 24) {
greeting = "Nej det är:";
} else if (day === 24 && month === 0) { // supposed to be january for example
greeting = "Ja!";
document.getElementById("clockdiv").style.visibility = "hidden";
}
document.getElementById("demo").innerHTML = greeting;
答案 3 :(得分:0)
感谢所有答案,我将所有答案结合起来并提出了解决方案。在这里。 Js小提琴:https://jsfiddle.net/linushg111/o6u8quwz/
var date = new Date();
var day = date.getDate();
var n = date.getMonth();
var greeting;
if (day === 24 && n === 11) {
greeting = "YES";
} else {
greeting = "NO :-(";
}
document.getElementById("demo").innerHTML = greeting;