Blogger Information
Blog 21
fans 0
comment 0
visits 20133
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
javascript语法
电动机的博客
Original
630 people have browsed it

总结

1、switch (n){  case 1:     case 2:      .....deault:  }

2、 for (var i = 0; i < Things.length; i++) {}

3、while(i < Things.length){ ...... i++}

4、do{ ...... i++}   }while((i < Things.length)

5、for(var in object){......} 遍历出对象、数组中每个键值对,var是对象、数据的下标  表达式:object[var]

6、break直接跳出最近的循环;continue 跳出循环的一个迭代,循环还继续

7、函数 :自定义函数 function name(参数序列){......}

                 匿名函数  var fun=function(){......},直接用变量调用

                 构造函数 Function(.......) ,直接在括号中执行

8、return :函数中碰到return就跳出函数,后面的语句不执行; return 可以带返回值并回传给函数的调用处

实例

<!DOCTYPE html>
<html>
<head>
	<title>3.27作业</title>
</head>

<!-- 九九乘法口令函数 其中:x为最大乘数-->
<script type="text/javascript">
	function mulTable(x){
         for (var i = 1; i <=x; i++) {
         	for (var j = 1; j <=i; j++) {
         		var space='   '
         		if (i*j<10) {
         			space +='  '
         		}
         		document.write(i+'x'+j+'='+(i*j)+space)
         	}
          document.write('<br>');
        
         }
	}
// 三角形函数 其中 z为三角形的行次数
 	function triangle(z){
		var i=0,x='*';
		while(i<z){
			document.write(x+'<br>');
			x=x+'**';	
		    i++;
		}	
	}
</script>
<body>
	<div>
        <script type="text/javascript">
	        mulTable(9);
        </script>
    </div>
    <div style="text-align: center;">
        <script type="text/javascript"> 
	        triangle(20)
        </script>
	</div>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

,return后面可以带返回值

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!