我遇到了一个 JavaScript 定时输出的问题,它说明了某种类型的问候,然后是时间。代码:
<script language="Javascript">
<!--
{
var now = new Date();
var h = now.getHours();
var m = now.getMinutes();
var s = now.getSeconds();
if (hours < 7){timemsg = "Wakey wakey, Mr. Person. The time is: " + hours + ':' + minutes + ':' + seconds};
if (hours > 6 && hours <12){timemsg = "Good morning, Mr. Person. The time is: " hours + ':' + minutes + ':' + seconds};
if (hours > 11 && hours <18){timemsg = "Good afternoon, Mr. Person. The time is: " hours + ':' + minutes + ':' + seconds};
if (hours >17){timemsg = "Good evening, Mr. Person. The time is: " hours + ':' + minutes + ':' + seconds};
document.write(timemsg)};
// -->
</script>
预期的输出应该是这样的:Wakey Wakey,/早上好/下午/晚上,先生。时间是:(时间)。