<html>
<body>
<p>点击按钮执行循环,并在 i 等于 “3” 的时候跳出循环。</p>
<button onclick="myFunction()">点我</button>
<p id="demo"></p>
<script>
function myFunction() {
var text = ""
var i;
for (i = 0; i < 5; i++) {
if (i == 3) {
break;
}
text += "The number is " + i + "<br>";
}
document.getElementById("demo").innerHTML = text;
}
</script>
</body>
</html>