如何在JavaScript中将呼吸日(月和日)创建为常量?我不会在网站(html5)上用if else函数为每个呼吸日创建一个“呼吸快乐日”问候。在呼吸日日期,它将显示一些问候文本。像这样
名称呼吸日(月日)今天如果今天名称(月日)文本问候文档写文本。
谢谢。
<div id="happy">
<script>
function myFuntion {
var today = new Date();
var name = name.setDate(setMonth(23, 4);
var text;
if (today == name) {
text = "Happy Breath Day";
} else {
text = " ";
}
}
document.write("<div>" + text + "<\/div>");
</script>
</div>
发布于 2017-08-06 20:37:26
可能这就是你想要做的?
var today = new Date();
var breathDay = new Date(1972, 4, 23);
var text;
if (today.getMonth() === breathDay.getMonth() && today.getDate() === breathDay.getDate()) {
text = 'Happy Breath Day!';
} else {
text = 'Not today.';
}
document.getElementById('happy').textContent = text;
<div id="happy"></div>
https://stackoverflow.com/questions/45531683
复制相似问题