简单教程
提交运行
代码编辑器:
<p>点击按钮根据不同的工作日输出信息</p> <button onclick="myFunction()">点我</button> <p id="demo"></p> <script> function myFunction() { var text; switch (new Date().getDay()) { case 6: text = "Today is Saturday"; break; case 0: text = "Today is Sunday"; break; default: text = "Looking forward to the Weekend"; } document.getElementById("demo").innerHTML = text; } </script>
运行结果: