<!DOCTYPE HTML> <html> <head> <title>demo</title> <meta charset="utf-8"/> <script> /* ** 语句 ** */ //(1) if...else.. /* var x = 3; if(x == 4){ alert("yes"); }else{ alert("no"); }//no */ /* var x = 3; if( x=4 ){ //此处不会报错, 而是会进行类型的转换, 返回true alert("yes"); }else{ alert("no"); } */ //(2) switch语句 /*var color = "yellow"; switch(color){ case "blue": alert("小蓝");break; case "red": alert("小红"); break; case "yellow": alert("大黄"); break; }*/ //(3)循环语句 while var i = 0; while(i<5){ //alert("hello js..."); console.log("hello js..."+i); i++; } //(4)for循环语句 var j = 0; for(var i=0; i<5; i++){ console.log("hello js...(for)"+i); } //注意JS中没有增强for循环 </script> </head> <body> 引入JS..... </body> </html>
|
|