1
<p>点击这个按钮,获得基于时间的问候。</p>
2
<button onclick="myFunction()">点击这里</button>
3
<p id="demo"></p>
4
<script>
5
function myFunction() {
6
var x = "";
7
var time = new Date().getHours();
8
if (time < 20) {
9
x = "Good day";
10
} else {
11
x = "Good evening";
12
}
13
document.getElementById("demo").innerHTML = x;
14
}
15
</script>