Switch 语句

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p id="demo"></p>
  6.  
  7. <script>
  8. var day;
  9. switch (new Date().getDay()) {
  10. case 0:
  11. day = "周日";
  12. break;
  13. case 1:
  14. day = "周一";
  15. break;
  16. case 2:
  17. day = "周二";
  18. break;
  19. case 3:
  20. day = "周三";
  21. break;
  22. case 4:
  23. day = "周四";
  24. break;
  25. case 5:
  26. day = "周五";
  27. break;
  28. case 6:
  29. day = "周六";
  30. }
  31. document.getElementById("demo").innerHTML = "今天是" + day;
  32. </script>
  33.  
  34. </body>
  35. </html>