document.forms用法示例介紹


轉自: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 >


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM