编辑下面的代码:【加编码】
<html> <body> <p>点击按钮根据时间输出问候语。</p> <button onclick="myFunction()">点我</button> <p id="demo"></p> <script> function myFunction() { var time = new Date().getHours(); var greeting; if (time < 10) { greeting = "Good morning"; } else if (time < 20) { greeting = "Good day"; } else { greeting ="Good evening"; } document.getElementById("demo").innerHTML = greeting; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂