Home  >  Article  >  Web Front-end  >  Document.forms usage examples introduction_javascript skills

Document.forms usage examples introduction_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:43:071789browse

Overview

forms returns a collection (an HTMLCollection object) that contains all 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']; //获取name为form1的form表单 
//或者 
//var thisForm = document.forms[0]; //获取第一个form表单 
console.info(thisForm.username.value); //输出表单name属性值为form1的 username的值 
console.info(thisForm.address.value); 
document.forms[0].submit(); //表单提交 
}) 
</script>
<body> 
<!-- 以下为三个简单的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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn