简单教程
提交运行
代码编辑器:
<p>点击按钮根据时间输出问候语</p> <button onclick="myFunction()">点我</button> <p id="demo"></p> <script> function myFunction() { var time = new Date().getHours(); var greeting; if (time < 20) { greeting = "Good day"; } else { greeting = "Good evening"; } document.getElementById("demo").innerHTML = greeting; } </script>
运行结果: