显示具有特定标签名称的元素数量
- <html>
- <head>
- <script type="text/javascript">
- function getElements()
- {
- var x=document.getElementsByTagName("input");
- alert(x.length);
- }
- </script>
- </head>
- <body>
- <input name="myInput" type="text" size="20" /><br />
- <input name="myInput" type="text" size="20" /><br />
- <input name="myInput" type="text" size="20" /><br />
- <br />
- <input type="button" onclick="getElements()" value="How many input elements?" />
- </body>
- </html>