日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

html5--switch选择结构的优化

發布時間:2023/12/15 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html5--switch选择结构的优化 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

html5--switch選擇結構的優化

?

問題:

使用循環語句判斷月份是31天還是30天

兩點提示:

  • 使用switch多條件判斷語句
  • 合理的省略break優化代碼
  • ?

    ?

    ?

    1 <!DOCTYPE html> 2 <html lang="zh-cn"> 3 <head> 4 <meta charset="utf-8"> 5 <title>7-19 課堂演示</title> 6 <link rel="stylesheet" type="text/css" href="style.css"> 7 </head> 8 <body> 9 <script> 10 // for(i=1;i<=50;i++){ 11 // if(i%3==0) { 12 // document.write(i+'<br>') 13 // } 14 // } 15 </script> 16 17 <script> 18 // var month=2; 19 // var num; 20 // switch(month){ 21 // case 1: 22 // num=31; 23 // alert(num); 24 // break; 25 // case 3: 26 // num=31; 27 // alert(num); 28 // break; 29 // case 5: 30 // num=31; 31 // alert(month+"月有:"+ num+"天"); 32 // break; 33 // case 7: 34 // num=31; 35 // alert(num); 36 // break; 37 // case 8: 38 // num=31; 39 // alert(num); 40 // break; 41 // case 10: 42 // num=31; 43 // alert(num); 44 // break; 45 // case 12: 46 // num=31; 47 // alert(num); 48 // break; 49 // case 4: 50 // num=30; 51 // alert(num); 52 // break; 53 // case 6: 54 // num=30; 55 // alert(num); 56 // break; 57 // case 9: 58 // num=30; 59 // alert(num); 60 // break; 61 // case 11: 62 // num=30; 63 // alert(num); 64 // break; 65 // case 8: 66 // num=30; 67 // alert(num); 68 // break; 69 // case 10: 70 // num=30; 71 // alert(num); 72 // break; 73 // case 12: 74 // num=30; 75 // alert(num); 76 // break; 77 // case 2: 78 // num="28或29" 79 // alert(num); 80 // } 81 </script> 82 <script> 83 var month=2; 84 var num; 85 switch(month){ 86 case 1: 87 case 3: 88 case 5: 89 case 7: 90 case 8: 91 case 10: 92 case 12: 93 num=31; 94 alert(month+"月有:"+ num+""); 95 break; 96 case 4: 97 case 6: 98 case 9: 99 case 11: 100 case 8: 101 case 10: 102 case 12: 103 num=30; 104 alert(month+"月有:"+ num+""); 105 break; 106 case 2: 107 num="28或29" 108 alert(month+"月有:"+ num+""); 109 } 110 </script> 111 </body> 112 </html> View Code

    ?

    轉載于:https://www.cnblogs.com/Renyi-Fan/p/8068337.html

    總結

    以上是生活随笔為你收集整理的html5--switch选择结构的优化的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。