Blogger Information
Blog 12
fans 0
comment 4
visits 9519
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Javascript第二篇——循环
温度的博客
Original
756 people have browsed it
	//九九乘法表
	for(i=1; i<=9;i++){   
		for(j=1;j<=9;j++){
			var kong = '&nbsp;&nbsp;&nbsp;';
			if(i*j<10){ //结果小于10在多加两个空格,保持对齐
				kong += '&nbsp;&nbsp;';
			}
			document.write(i+'*'+j+'='+i*j+kong);
			if(i==j){  //如果两个乘数相同,则另起一行,break跳出循环
				{document.write('<br>');break};
			}
		}

	}

	//三角形
	function xing(x){
		var num = 1; //星星数
		var str = '';  //星星
		while(num<x){
			str += "*";  // 拼接星星字符串
			document.write("<div style='text-align:center'>"+str+"</div>");
			num++;
		}
	}
	xing(30); //传参,最后一行多少个星星


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