简单教程
提交运行
代码编辑器:
<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>
运行结果: