网页编程的问题 急

来源:百度知道 编辑:UC知道 时间:2024/05/14 16:19:14
<html>
<head>
<title>sj</title>
<meta http-equiv="refresh" content="2">
</head>
<body>
<script language="javascript">
var now=newDate();
var hour=now.getHOURS();
if(hour>=0&&hour<=12)
document.write("上午好");
if(hour>=12&&hour<=18)
document.write("下午好");
if(hour>=18&&hour<=24)
document.write("晚上好");
document.write("<p> 今天是:"+now.getYear()+" 年 "+now.getMonth()+1" 月 "+now.getDate()+" 日 "+now.getDay()+"星期");
</script>
</body>
</html>

问题是 编写一个程序,在页面中显示:今天是年x月x日x星期x上午/下午/晚上好

请问上面的程序错在哪?应该是什么?该怎么改?

<html>
<head>
<title>sj</title>
</head>
<body>
<script language="javascript">
var now = new Date();
var hour = now.getHours();
if(hour >= 0 && hour < 12) {document.write("上午好");}
else if(hour >= 12 && hour < 18) {document.write("下午好"); }
else {document.write("晚上好");}
document.write("<p> 今天是:" + now.getYear() + " 年 " + (now.getMonth()+1) + " 月 "+now.getDate()+" 日 " +"星期" + now.getDay());
</script>
</body>
</html>

另外, 没必要加 <meta http-equiv="refresh" content="2"> 哈

跨几个小时的, 没2秒刷新一次, 没意义

算秒的话, 这样刷新会导致页面整体刷新, 也没有意义