编辑下面的代码:【加编码】
<html> <body> <p>点击按钮显示今天是星期几。</p> <button onclick="myFunction()">点我</button> <p id="demo"></p> <script> function myFunction() { var day; switch (new Date().getDay()) { case 0: day = "Sunday"; break; case 1: day = "Monday"; break; case 2: day = "Tuesday"; break; case 3: day = "Wednesday"; break; case 4: day = "Thursday"; break; case 5: day = "Friday"; break; case 6: day = "Saturday"; break; } document.getElementById("demo").innerHTML = "Today is " + day; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂