A sample introduction to the use of document.forms

  • 2020-03-30 03:29:17
  • OfStack

An overview of the

Forms returns a collection (an HTMLCollection object) that contains all the form elements in the current document.

grammar

Var collection = document. Forms;

example

Get form information


<script type="text/javascript"> 
$(function(){ 
var thisForm = document.forms['form1']; //Gets the form form with the name form1
// or  
//var thisForm = document.forms[0]; // Get the first one form The form  
console.info(thisForm.username.value); //Output the value of username with the form name attribute value of form1
console.info(thisForm.address.value); 
document.forms[0].submit(); //The form submission
}) 
</script>
<body> 
<!--  Here are three simple ones form The form  --> 
<form action="x" name="form1" > 
<input type="text" name="username" value="zhangsan" /> 
<input type="text" name="address" value="beijing" /> 
</form> 

<form action="x" name="form2" > 
</form> 

<form action="x" name="form3" > 
</form> 
</body>

Related articles: