JavaScript--文法2--語句結構

來源:互聯網
上載者:User

標籤:logs   java   支援   tle   弱類型   html   str   迴圈   code   

JavaScript--文法2一、心得

判斷的時候常量放左邊
java中switch只支援四種類型,javaScript是弱類型,所有的都支援。

顯示方法:

 77 //                alert("x="+x); 78                 //將資料直接寫到當前頁面當中。 79                 document.write("x="+x+"<br/>");
二、代碼
  1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">  2 <html>  3     <head>  4         <meta http-equiv="Content-Type" content="text/html; charset=GBK">  5         <title>Untitled Document</title>  6     </head>  7     <body>  8         <script type="text/javascript">  9             /* 10              * 語句: 11              * 1,順序結構。 12              *      13              * 2,判斷結構。 14              *         代表語句: if. 15              * 3,選擇結構。 16              *         switch 17              * 4,迴圈結構。 18              *         while  do while  for 19              * 5,其他語句。 20              *         break:跳出選擇,跳出迴圈。 21              *         continue:用於迴圈語句,結束本次迴圈繼續下次迴圈。  22              */ 23              24 //            alert("abc1"); 25 //            alert("abc2"); 26          27          28 //            ------------------------------------------------ 29             /* 30             var x = 3; 31 //            if(x=4){//注意。 32             if(4==x){//建議將常量放左邊。以報錯來修正代碼。 33                 alert("yes"); 34             }else{ 35                 alert("no"); 36             } 37              38              39              40             if(x>1) 41                 alert("a"); 42             else if(x>2) 43                 alert("b"); 44             else if(x>3) 45                 alert("c"); 46             else 47                 alert("d"); 48                  49             */     50          51 //            ------------------------------------------------ 52             /* 53             //選擇結構。 54             var x = "abc"; 55             switch(x){ 56                  57                 case "kk": 58                     alert("a"); 59                     break; 60                 case "abc": 61                     alert("b"); 62                     break; 63                 default: 64                     alert("c"); 65                     break;//省略。因為是最後一個語句,後面就是大括弧了     66             } 67             */ 68              69              70              71             //迴圈結構。 72             /* 73             var x = 1; 74             document.write("<font color=‘blue‘ >");//顏色控制,html內容 75             while(x<10) 76             { 77 //                alert("x="+x); 78                 //將資料直接寫到當前頁面當中。 79                 document.write("x="+x+"<br/>"); 80                 x++; 81             } 82             document.write("</font>"); 83              84              85             for(var x=0; x<3; x++){ 86                 document.write("x="+x); 87             } 88             */ 89              90              91             /* 92             w:for(var x=0; x<3; x++){//標號 93                 for(var y=0; y<4; y++){ 94                     document.write("x==="+x); 95                     continue w;//跳出當前迴圈。 96                 } 97             } 98             */ 99             100             101         </script>102         103         104         105         106     </body>107 </html>

 

JavaScript--文法2--語句結構

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.