Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Document.forms

概述

forms 返回一个包含了当前文档中的所有 form 元素的集合 (一个HTMLCollection对象),。

语法

var collection = document.forms; 

例子: 获取表单信息

<html>

<head>
<title> document.forms example</title>
</head>

<body>
<form id="robby">
 <input type="button" onclick="alert(document.forms[0].id);"
 value="robby's form" />
</form>

<form id="dave">
 <input type="button" onclick="alert(document.forms[1].id);"
 value="dave's form" />
</form>

<form id="paul">
 <input type="button" onclick="alert(document.forms[2].id);"
 value="paul's form" />
</form>

</body>
</html>

 例子: 获取表单内的元素

var selectForm = document.forms[index];
var selectFormElement = document.forms[index].elements[index];

规范

forms DOM Level 2 HTML: forms

相关链接

文档标签和贡献者

 此页面的贡献者: helloguangxue, teoli, khalid32, AlexChao, ziyunfei
 最后编辑者: helloguangxue,