代码示例:(标识:jsck_state_if)
<!DOCTYPE html>
<html>
<body>

<p>单击按钮显示 "Good day",仅当时间小于 20:00 时。</p>

<button onclick="myFunction()">试一试</button>

<p id="demo"></p>

<script>
function myFunction() {
  var time = new Date().getHours();
  if (time < 20) {
    document.getElementById("demo").innerHTML = "Good day";
  }
}
</script>

</body>
</html>
运行结果: