概述
forms 返回一個集合(一個HTMLCollection對象),包含了了當前文檔中的所有form元素.
文法
var collection = document.forms;
例子
獲取表單信息
<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>