<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>百宝箱工作室IT微课堂 http://www.baibaox.com</title>
</head>
<body>
<p>点击按钮,测试带有 break 语句的循环。</p>
<button onclick="myFunction()">点我看看</button>
<p id="demo"></p>
<script>
function myFunction()
{
var x="",i=1;
//当1<=1<=10时,for循环会被执行
for (i=1;i<=10;i++)
{
//当i=5时,跳出for循环,即停止执行for循环
if (i==5)
{
break;
}
//字符串拼接
x=x + "第" + i + "次执行for循环<br>";
}
//在指定标签输出x
document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html>
