代码示例:(标识:jsck_nodelist_length_p_loop)
<!DOCTYPE html>
<html>
<body>
<h1>Nodelist 对象</h1>

<h2>length 属性</h2>

<button onclick="myFunction()">更改</button>

<p>请单击“更改”,来更改 "myDIV" 中所有 p 元素的字体大小。</p>

<div id="myDIV" style="border:1px solid black; padding:16px;">
  <p>我是段落。。。</p>
  <p>我是段落。。。</p>
  <p>我是段落。。。</p>
</div>

<script>
function myFunction() {
  const div = document.getElementById("myDIV");
  const list = div.querySelectorAll("p");
  
  for (let i = 0; i < list.length; i++) {
    list[i].style.fontSize = "24px";
  }
}
</script>

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