HTML DOM forms collection
Definition and Usage
Return the current page collection forms an array of all forms of collection.
grammar
document.forms[].property
Browser Support
All major browsers support forms collection
Examples
Example 1
Returns the number of forms in the document:
<html>
<body>
<form name="Form1"></form>
<form name="Form2"></form>
<form></form>
<p>表单数目:
<script>
document.write(document.forms.length);
</script></p>
</body>
</html>
<body>
<form name="Form1"></form>
<form name="Form2"></form>
<form></form>
<p>表单数目:
<script>
document.write(document.forms.length);
</script></p>
</body>
</html>
Examples of the above output:
表单数目: 3
try it"
Example 2
Returns the name of the first document in the form of:
<html>
<body>
<form name="Form1"></form>
<form name="Form2"></form>
<form></form>
<p>第一个表单名称:
<script>
document.write(document.forms[0].name);
</script></p>
</body>
</html>
<body>
<form name="Form1"></form>
<form name="Form2"></form>
<form></form>
<p>第一个表单名称:
<script>
document.write(document.forms[0].name);
</script></p>
</body>
</html>
Examples of the above output:
第一个表单名称: Form1
try it"
Document Object