1
<p>如果时间早于 20:00,会获得问候 "Good day"。</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
}
11
document.getElementById("demo").innerHTML = x;
12
}
13
</script>