Web開発コード:Forループ:ループのために、5回のコードブロックのループを実行するためのボタンをクリックしてください:限り、私は6未満であるように、コードブロックを循環されています:ループは一方で、1-6のショーからHTMLタイトルのスタイルを設定するには、ボタンをクリックしてください

1、ループの場合:コードブロックのループを実行するために5回ボタンをクリックしてください

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>now test</title> 

</head>
<body>
		<p>单击按钮将代码块循环执行5次。</p>
		<button onclick="myFunction()">点我</button>
		<p id="demo"></p>
<script>
function myFunction(){
	var x="",i;
	for (i=0;i<5;i++){
		x=x+"这个数字是"+i+"<br>";
	}
	document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html> 

2、ループの場合:表示スタイル1-6からHTMLのタイトルを設定するには、ボタンをクリックしてください

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>now test</title> 

</head>
<body>
		<p>单击按钮将HTML标题设置从1到6的样式显示</p>
		<button onclick="myFunction()">点我点我</button>
		<div id="demo"></div>
<script>
function myFunction(){
	var x="",i;
	for (i=1;i<6;i++){
		x=x+"<h"+i+">Heading"+i+"</h"+i+">";
	}
	document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html> 

図3に示すように、サイクル中:限りiが6未満の巡回符号ブロックであるようになっています

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>now test</title> 

</head>
<body>
		<p>点击下面的按钮,只要 i 小于 6就一直循环代码块。</p>
		<button onclick="myFunction()">点我点我</button>
		<p id="demo"></p>
<script>
function myFunction(){
	var x="",i=0;
	while (i<6){
		x=x+"该数字为"+i+"<br>";
		i++;
	}
	document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html> 

図4に示すように、ループないが:iが6未満巡回符号ブロックされています

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>now test</title> 

</head>
<body>
		<p>点击下面的按钮,只要 i 小于 6就一直循环代码块。</p>
		<button onclick="myFunction()">点我点我</button>
		<p id="demo"></p>
<script>
function myFunction(){
	var x="",i=0;
	do {
		x=x+"该数字为"+i+"<br>";
		i++;
	}
	while (i<6)
	document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html> 

5、

おすすめ

転載: blog.csdn.net/weixin_43731793/article/details/93719690