代码示例:(标识:eg_js_fornext_header)
<!DOCTYPE html>
<html>
<body>

<p>单击按钮从 1 到 6 循环,以生成 HTML 标题。</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 + ">标题 " + i + "</h" + i + ">";
  }
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>
运行结果: