The example in this article describes the method of using JavaScript to obtain the number of forms on the page. Share it with everyone for your reference. The details are as follows:
The following JS code obtains the number of forms in the web page through the document.forms array
<!DOCTYPE html> <html> <body> <h1>sharejs.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>
The running results are as follows:
Number of forms: 3
I hope this article will be helpful to everyone’s JavaScript programming design.