Home > Web Front-end > JS Tutorial > body text

Document.forms usage examples introduction_javascript skills

WBOY
Release: 2016-05-16 16:43:07
Original
1788 people have browsed it

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!