x
 
<!DOCTYPE html>
<html>
<body>
<h1>HTMLCollection length 属性</h1>
<p>length 属性返回 HTMLCollection 中元素的数量。</p>
<p>单击按钮可输出此文档中 P 元素的数量:</p>
<button onclick="myFunction()">对 P 元素计数</button>
<script>
function myFunction() {
  var l = document.getElementsByTagName("P").length;
  alert(l);
}
</script>
</body>
</html>