我有一个index.html
,在此文件中,我编写代码以便在此显示一条消息“hello”。我的目标是实现显示三种消息的代码:“早上好”,“晚上好”和“晚安”。如何通过Javascript中的if语句显示消息
跟随我的代码:
<p id="show_time" class="time"></p>
<script>
window.onload = show_time('show_time');
function show_time(id) {
h = date.getHours();
if h == 22 {
document.getElementById(id).innerHTML = "hello";
}
setTimeout('show_time("' + id + '");','1000');
return true;
}
}
在这段代码中我只写了一个情况。类,时间是包含字体大小和字体系列的css
属性。 h
获取当前小时,如果h
为22,则将输出“hello”。但这不起作用。
如果您可以提供显示三种消息类型的代码,它非常有用。
谢谢
'H> 0 &&ħ<= 16'节目( “早上好”)。 “h> 16 && h <= 20”表演(“晚上好”)。 'h> 20 && h <= 24'表演(“晚安”)。像这样? –
写在如果不合格。 'if(h == 22){// your code}' –
if(h == 22){will工作 –