下面的JS代码通过document.forms数组获得网页中表单(form)的数量
<!DOCTYPE html> <html> <body> <h1>75271.com</h1> <form name="Form1"></form> <form name="Form2"></form> <form></form> <p>Number of forms: <script> document.write(document.forms.length); </script></p> </body> </html>
上面的代码浏览后显示
Number of forms: 3