源代码 :
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>开源教程(ossoft.cn)</title> <script> function getElements(){ var x=document.getElementsByTagName("input"); alert(x.length); } </script> </head> <body> <input type="text" size="20"><br> <input type="text" size="20"><br> <input type="text" size="20"><br><br> <input type="button" onclick="getElements()" value="多少input元素?"> </body> </html>
运行结果