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