源代碼
點擊運行
<html> <head> <meta charset="utf-8"> <title>教程</title> </head> <body> <p>點擊下面的按鈕,會顯示出基於今日日期的消息:</p> <button onclick="myFunction()">點擊這里</button> <p id="demo"></p> <script> function myFunction() { var x; var d=new Date().getDay(); switch (d) { case 6:x="今天是星期六"; break; case 0:x="今天是星期日"; break; default: x="期待周末"; } document.getElementById("demo").innerHTML=x; } </script> </body> </html>
運行結果