显示具有特定标签名称的元素数量

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function getElements()
  5. {
  6. var x=document.getElementsByTagName("input");
  7. alert(x.length);
  8. }
  9. </script>
  10. </head>
  11. <body>
  12.  
  13. <input name="myInput" type="text" size="20" /><br />
  14. <input name="myInput" type="text" size="20" /><br />
  15. <input name="myInput" type="text" size="20" /><br />
  16. <br />
  17. <input type="button" onclick="getElements()" value="How many input elements?" />
  18.  
  19. </body>
  20. </html>