Blogger Information
Blog 20
fans 0
comment 0
visits 39919
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JavaScript基础第二节/switch、for循环、函数、作业2019年4月1日18时01分
Time
Original
1196 people have browsed it

实例

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	<script>

				// switch

				//break 跳出整个 停止switch  continue 跳过本条 继续向后执行  default 什么都没选中到此处

	var baozi=4;

  	switch(baozi){

  		case 1:document.write('吃一个!');

  		break;

        case 2:document.write('吃两个!');

  		break;

  		case 3:document.write('吃三个!');

  		break;

        case 4:document.write('吃四个!');

  		break;

  		default:document.write('吃duo个');

  	}

		</script>
	</head>
          <body>
	</body>

</html>

运行实例 »

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

实例

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
<script>
	//乘法表
			var a,b;
			for (a=1;a<=9;a++) {
				document.write('<br />')
				for (b=1;b<=a;b++) {
					lasy=a*b;
					document.write(a,'x',b,'=',lasy, ' ')
				}
			}
	//三角形
	document.write('<br />');
		
			var t = 1;
			while(t<=10){
				var m = 1;
				document.write('<center>');
				while(m<=t){
					document.write('*')
					m++;
				}
				document.write("<br/>");
				t++;
				document.write('</center>');
							}
</script>
	</head>
		
	<body style="padding: 20px;">
		
	</body>

</html>

运行实例 »

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

实例

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
<script>
var la =1;
	while(la<=10){
		document.write(la+"<br />");
		la++;
	}
	//do while
	var ls = 1;
	do{
		document.write(ls+"<br />");
		ls++;
	}while (ls<=5);</script>
	
	</head>
		
	<body style="padding: 20px;">
		
	</body>

</html>

运行实例 »

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

实例

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
<script>
//break 跳出整个 停止switch  continue 跳过本条 继续向后执行  default 什么都没选中到此处
		//do while
	var ls = 1;
	do{
		document.write(ls+"<br />");
		ls++;
	}while (ls<=5);
	//for ...in 用于循环对象属性( for...in 循环中的代码块将针对每个属性执行一次)
var las0=["html","css","JavaScript","jquery","php","mysqli","json","ajax"];
    var x
    for(x in las0){
    	document.write(las0[x]+'<br>')
    }
//函数 1、只有被调用了才会运行 2函数可以通过一个表达式定义,函数表达式可以存储在变量中
// Function()构造函数  大写
// var obj=new Function(document.write('Time'))
// obj()
  //   形参:形式参数,函数名后面的括号中的参数
  //   实参:实际参数,是指函数在调用的时候,函数名后面的括号中的参数,它的作用是将函数外面的变量通过实参穿入到函数中。


	function showSjx(){
			var t = 1;
		while(t<=10){
			var m = 1;
			document.write('<center>');
			while(m<=t){
				document.write('*')
				m++;
			}
			document.write("<br/>");
			t++;
			document.write('</center>');
						}
	}
	showSjx();
	
	function names(x,y){
		document.write(x+y)
		
	}
 names(10,5)
 document.write('<br />');
	function lasa(c,d){
		document.write('nbs');
		return c*d;
	}
	document.write(lasa(10,2));
		</script>
	</head>
		
	<body style="padding: 20px;">
		
	</body>

</html>

运行实例 »

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

 

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