轉自:https://blog.csdn.net/h12kjgj/article/details/61624509
概述
forms 返回一個集合 (一個HTMLCollection對象),包含了了當前文檔中的所有form元素.
語法
var collection = document.forms;
document.forms['exportServlet'].submit();
(1)document.forms:表示獲取當前頁面的所有表單
(2)document.forms[0]:表示獲取當前頁面的第一個表單
(3)document.forms['exportServlet']:表示獲取當前頁面的name="exportServlet"的表單
(4)submit()表示提交函數
例子
注意:get請求表單的action屬性后不能帶參數
獲取表單信息
<
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
>
<
form
action
=
"x"
name
=
"form1"
>
<
input
type
=
"text"
name
=
"username"
value
=
"zhangsan"
/>
<
input
type
=
"text"
name
=
"address"
value
=
"beijing"
/>
</
form
>
|
