微信扫一扫打赏支持

JavaScript--语法2--语句结构

JavaScript--语句结构

一、心得

判断的时候常量放左边
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>

 

posted @ 2017-06-21 16:15  范仁义  阅读(585)  评论(0编辑  收藏  举报