案例:javascript案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<p>点击这个按钮,获得基于时间的问候。</p>
6
7
<button onclick="myFunction()">点击这里</button>
8
9
<p id="demo"></p>
10
11
<script>
12
function myFunction()
13
{
14
var x="";
15
var time=new Date().getHours();
16
if (time<10)
17
  {
18
  x="Good morning";
19
  }
20
else if (time<20)
21
  {
22
  x="Good day";
23
  }
24
else
25
  {
26
  x="Good evening";
27
  }
28
document.getElementById("demo").innerHTML=x;
29
}
30
</script>
31
32
</body>
33
</html>
34