17.demo.html 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. // 案例1:进入页面 输入月份 页面显示当前月份及月份的天数;
  11. // var month = prompt("请输入月份");
  12. // // console.log(month);
  13. // switch(month) {
  14. // case "1":
  15. // case "3":
  16. // case "5":
  17. // case "7":
  18. // case "8":
  19. // case "10":
  20. // case "12":
  21. // console.log(month + "月份有31天");
  22. // break;
  23. // case 2:
  24. // console.log(month + "月份有19天");
  25. // break;
  26. // case "4":
  27. // case "6":
  28. // case "9":
  29. // case "11":
  30. // console.log(month + "月份有30天");
  31. // break;
  32. // default:
  33. // console.log("请输入正确的月份");
  34. // break;
  35. // }
  36. // 案例2:进入页面 输入年份 页面显示当前年月及平年/闰年;
  37. // var year = prompt("请输入年份");
  38. // console.log(year);
  39. // if(year % 400 == 0 || year % 4 == 0 && year % 100 != 0) {
  40. // alert(year + "年是闰年");
  41. // } else {
  42. // alert(year + "年是平年");
  43. // }
  44. // 案例三:进入页面 输入三角形的宽高 弹出三角形的面积 函数
  45. function fn1() {
  46. var width = prompt("请输入宽度");
  47. var height = prompt("请输入高度");
  48. var area = (width * height) / 2;
  49. alert(area);
  50. }
  51. fn1();
  52. </script>
  53. </body>
  54. </html>