-
2017-06-15 22:07:18
本文转载自:IT摆渡网 --一个按难度收费的IT实时问答平台!快速解决你的任何技术问题!-- www.itbaiduwang.com
如果是PHP的网页,比如**.php,那么只有网页没有任何输出的时候,才能自动提交!而且要没有submit这个按钮才能自动提交,比如下面这样:
<form name="form1" id="form1" method="post" action="" target="_self">
<input type="hidden" name="pGateWayReq" value="" />
</form>
<script language="javascript">document.form1.submit();</script>
只有这样,才可以自动提交!
更多相关内容 -
document.form.action,表单分向提交,javascript提交表单
2017-12-21 22:20:07document.form.action,表单分向提交,javascript提交表单 同一个表单可以根据用户的选择,提交给不同的后台处理程序。即,表单的分向提交。如,在编写论坛程序时,如果我们希望实现用户在发送贴子的时候,既发送提交...document.form.action,表单分向提交,javascript提交表单
同一个表单可以根据用户的选择,提交给不同的后台处理程序。即,表单的分向提交。如,在编写论坛程序时,如果我们希望实现用户在发送贴子的时候,既发送提交功能又有预览功能时,就会遇到上述问题。即,当用户点击提交按钮时,我们希望表单提交给"提交"处理程序;而当用户点击预览按钮时,我们希望表单提交给"预览"处理程序。那么,如何实现上述功能呢?下面代码可以很好的解决这个问题。
<form name="form" method="post"> 测试表单:<input name="test"><br> <input type="button" value="提交" onClick=send()> <input type="button" value="预览" onClick=preview()> </form> <script language=javascript> function send() { document.form.action="send.asp" document.form.submit() } function preview() { document.form.action="preview.asp" document.form.submit() } </script>
关于上面实例的两点说明:
1、在整个表单中,不应有名字为action或submit的标签,否则将会产生"对象不支持此属性和方法"的错误。如代码 "<input type='xxxx' name='action' >"在表单中是不允许出现的;
2、在form标签中应该存在name属性。即,应该给表单取一个名字。语句document.form.action和document.form.submit中的"form"也就是表单的名字。
表单的分向提交不仅仅使用在论坛的程序中,它还可以运用在许多场合下。恰当的运用表单的分向提交功能可以大大的增强网站的人性化程度。
昨天,我调试程序就出现了这样的问题,就是出现了"对象不支持此属性和方法"的错误,一直无法定位出来,都快疯掉了,后来在发现一个button命名为submit了。
<form name="formname" action=""> <input name="inputname"> <input type="submit" οnclick="document.formname.action='a.asp'" value="button a"> <input type="submit" οnclick="document.formname.action='b.asp'" value="button b"> <input type="submit" οnclick="document.formname.action='c.asp'" value="button c"> </form> 2.---------- <input type=button name="a" value="a" οnclick="this.form.action='a.asp';this.form.submit();"> <input type=button name="b" value="b" οnclick="this.form.action='b.asp';this.form.submit();"> <input type=button name="c" value="c" οnclick="this.form.action='c.asp';this.form.submit();"> <input type=button name="d" value="d" οnclick="this.form.action='d.asp';this.form.submit();">
转载连接: 原文链接
-
让你一次了解document.forms和document.formName的兼容性
2018-11-16 11:17:33今天在代码中不小心写了两个name相同的form表单,然后通过document.forms[formName]形式获取到的只有第一个表单,然后深入学习了下document.forms[formName]和document.formName的区别和兼容性。 下面先测试了下...今天在代码中不小心写了两个name相同的form表单,然后通过document.forms[formName]形式获取到的只有第一个表单,然后深入学习了下document.forms[formName]和document.formName的区别和兼容性。
下面先测试了下document.forms[formName]、document.forms.formName、document.formName、document.forms(formName)的兼容性
一、当表单name唯一时<form action="test1" name="test">test1</form>
IE8下
IE9下
firefox下,版本63.0.1
chrome下,版本68.0.3340.75
safari下,版本11.1.2测试发现:当表单name唯一时,在IE8版本,获取表单的所有方法得到的是一个object对象,通过这个object无法获取表单,而在firefox、chrome和safari下,不支持document.forms(formName)的形式获取表单
二、当表单name不唯一时
<form action="test1" name="test">test1</form> <form action="test2" name="test">test2</form>
IE8下
IE8下,获取获取第二个表单
IE9下
IE9下,获取第二个表单
firefox下
firefox下,获取第二个表单
chrome下
chrome下,获取第二个表单
safari下
safari下,获取第一个表单测试发现:当表单name不唯一时,IE9下四种方式都返回了一个HTMLCollection对象,通过HTMLCollection[1]的形式可以获取到第二个表单;在firefox、chrome和safari下,通过document.forms[formName]和document.forms.formName获取到的都是第一个表单,而不是一个HTMLCollection对象,也就是说,通过这两种方法是无法获取到第i(i>1)个表单元素到;在document.formName方法则无论是在IE9、firefox、chrome还是safari下,都能获取一个HTMLCollection对象,也就是说,可以通过这种方法,获取到name相同的所有表单。
结论:
通过以上兼容性的测试,在不考虑IE8的情况下,推荐使用document.formName的形式获取表单。
当表单name唯一时,通过document.formName的方法可获得该表单;
当表单name不唯一时,通过document.formName的方法可以获得一个HTMLCollection对象,通过HTMLCollection[i]的形式,可以获得第i个表单。document.formName.length结果是什么?
现在请思考下document.formName.length的结果是什么?是不是理所当然的想,当name唯一时,返回1;当name不唯一时,有多少个name=formName的表单就返回几。
我们还是用实例说话吧:<form name="test1"> <input type="text" name="age" /> <input type="text" /> <div>表单name唯一</div> </form> <form name="test2"> <input type="text" name="age" /> <input type="text" /> <div>表单name不唯一</div> </form> <form name="test2"> <input type="text" name="age" /> </form> document.test1.length // -->2 document.test2.length // -->2
实践后发现,当表单name唯一时,length为2;当name不唯一(有两个)时,也返回2。为什么呢?
当name唯一时,documen.formName返回的不是一个数组,所以一开始想得是length属性不存在,document.formName.length应该返回undefined,但是事实却不是这样。
当name唯一时,document.formName.length返回的是表单下输入框的元素个数,而当name不唯一时,返回的才是真正的表单个数。
那么如何判断表单的name属性是否唯一呢?
一般写使用表单的话,下面一定会有输入框,无论name属性是否唯一,document.formName[0]都有值,但是当name唯一下,document.formName[0][0]是没有元素的,即结果为undefined,而当name不唯一时,document.formName[0][0]返回的是第一个表单下的第一个子元素
因此,可以通过document.formName[0][0]来判断表单的name属性是否唯一,当返回结果为undefined时,则表示name属性唯一,否则即存在多个name相同当表单
延伸:
通过document.formName.elements[subName]或document.formName.subName的形式可以获取form下元素。
如:<form name="test"> <input type="text" name="myName" value="happy" /> </form> <script> document.test.myName.value // happy </script>
参考:
-
document.form.action,表单分向提交
2016-07-13 12:22:08document.form.action,表单分向提交,javascript提交表单 同一个表单可以根据用户的选择,提交给不同的后台处理程序。即,表单的分向提交。如,在编写论坛程序时,如果我们希望实现用户在发送贴子的时候,既发送提交...document.form.action,表单分向提交,javascript提交表单 同一个表单可以根据用户的选择,提交给不同的后台处理程序。即,表单的分向提交。如,在编写论坛程序时,如果我们希望实现用户在发送贴子的时候,既发送提交功能又有预览功能时,就会遇到上述问题。即,当用户点击提交按钮时,我们希望表单提交给"提交"处理程序;而当用户点击预览按钮时,我们希望表单提交给"预览"处理程序。那么,如何实现上述功能呢?下面代码可以很好的解决这个问题。 <form name="form" method="post"> 测试表单:<input name="test"><br> <input type="button" value="提交" onClick=send()> <input type="button" value="预览" onClick=preview()> </form> <script language=javascript> function send() { document.form.action="send.asp" document.form.submit() } function preview() { document.form.action="preview.asp" document.form.submit() } </script> 关于上面实例的两点说明: 1、在整个表单中,不应有名字为action或submit的标签,否则将会产生"对象不支持此属性和方法"的错误。如代码 "<input type='xxxx' name='action' >"在表单中是不允许出现的; 2、在form标签中应该存在name属性。即,应该给表单取一个名字。语句document.form.action和document.form.submit中的"form"也就是表单的名字。 表单的分向提交不仅仅使用在论坛的程序中,它还可以运用在许多场合下。恰当的运用表单的分向提交功能可以大大的增强网站的人性化程度。 昨天,我调试程序就出现了这样的问题,就是出现了"对象不支持此属性和方法"的错误,一直无法定位出来,都快疯掉了,后来在发现一个button命名为submit了。 1.-------- <form name="formname" action=""> <input name="inputname"> <input type="submit" οnclick="document.formname.action='a.asp'" value="button a"> <input type="submit" οnclick="document.formname.action='b.asp'" value="button b"> <input type="submit" οnclick="document.formname.action='c.asp'" value="button c"> </form> 2.---------- <input type=button name="a" value="a" οnclick="this.form.action='a.asp';this.form.submit();"> <input type=button name="b" value="b" οnclick="this.form.action='b.asp';this.form.submit();"> <input type=button name="c" value="c" οnclick="this.form.action='c.asp';this.form.submit();"> <input type=button name="d" value="d" οnclick="this.form.action='d.asp';this.form.submit();">
-
OnClick =“javascript:document.form1.submit()”提交表单给servlet并调用doPost()方法
2019-04-14 23:51:531.首先说说我遇到的问题:做毕设时,需要删除会员,我的想法是...(提示:关键语句:document.form1.submit()) 2.思路:点击删除---->弹出确认框---->确认---->调用表单---->通过表单的doPost()方法重... -
JS表单document.forms的用法(详解)
2020-08-13 11:18:48document.forms 表示获取当前页面的所有表单 document.forms[0] 表示获取当前页面的第一个表单 document.forms[‘exportServlet’] 表示获取当前页面的name="exportServlet"的表单 document.forms[... -
document.form.submit()的使用
2012-05-21 16:39:461、example: submit 参考:http://zhidao.baidu.com/question/96051969.html 2、。。 Html From 提交 关于Html form表单的提交,很容易。。。但如果不仔细还是能有很多错误 ... -
解决document.form.submit()对象不支持此属性或方法
2012-12-09 22:11:52有时候,用document.forms[0].submit() 或document.getElementById("formId").submit()方法时候,明明书写没有错误却总是报这个错误,说对象不支持此属性或方法。 在button的input中,name属性不要使用... -
彻底解决谷歌浏览器不支持 document.formname.submit() 的方法,绝对有效!
2012-12-04 10:32:25代码如下: name="submit" value="提交">...document._thisform.submit(); } 网上很多都说需要通过判断如果是谷歌浏览器则用ajax方式提交: $.post(); uncaught TypeError: Property 'sub -
document.forms用法示例介绍
2016-09-10 11:16:43forms 返回一个集合包含了了当前文档中的所有form元素,下面通过示例为大家介绍下document.forms用法, 概述 forms 返回一个集合 (一个HTMLCollection对象),包含了了当前文档中的所有form元素. 语法 var ... -
用document.forms[formname].elements[elementname].value获取FORM元素的value--测试通过
2014-06-03 10:51:04用新方法document取得FORM中的元素的value function sub() { var name = document.forms['theForm'].elements['name'].value; var sex = document.forms['theForm'].elements['sex'].value; alert(name); alert... -
原生javascript 表单同步提交和提交前操作 和 document.form.submit() is not a function
2017-07-13 16:34:30原生javascript 表单同步提交和提交前操作 var_dump($_POST); ?> function SendForm () { if(CheckPost()) { document.addForm.submit(); } } function Check -
document.forms的用法(详解)
2019-03-22 17:05:24document.forms 表示获取当前页面的所有表单 document.forms[0] 表示获取当前页面的第一个表单 document.forms[‘exportServlet’] 表示获取当前页面的name="exportServlet"的表单 document.forms[... -
document.forms[0].action所提交的内容
2018-06-25 19:07:03问题:forms[0]提交了form表单中的什么内容?<script type="text/javascript"> function doName(){ ...${basePath}/form_testForm.action"; document.forms[0].submit(); }... -
js动态生成form 并用ajax方式提交的实现方法
2020-11-24 03:10:50var tempForm = document.createElement("form"); tempForm.action="http://localhost:8080/test/user"; tempForm.method="post"; document.body.appendChild(tempForm); //create a submit... -
JS Error:'document.form.name' 为空或不是对象
2008-12-22 11:29:00Line:71Char:3Code:0Error:document.form.name 为空或不是对象网址:http://localhost/test/123.html 以下是代码,请大家帮帮忙,问题出在哪了。我是初学者,实在是弄不明白了。留言板function Agree_onclick() { ... -
document.getElementById()获取的值不对
2015-12-07 08:30:40document.form1.action = 'AutoBatchConfig_updateAutoBatchState.action?bc_id='+bc_id+'&bc_state'+bc_state; } <form action="" method="post" id="form1" name="form1"> ; overflow-y: auto; ... -
JS中用document对象操作form表单 案例
2017-08-24 18:06:11<!DOCTYPE html> 百度360一起搜 <!-- 作者:李瑞琦 时间:2017-08-24 描述:用document对象操作form表单 --> -
JavaScript常用内置对象(window、document、form对象)
2013-06-29 12:41:18<form name="frm" method="post" action=""> 用户名:<input type="text" name="userName"/><label id="errorMsg"></label><br/> 密码: <input type="password" name="password"/><br> 确定" onclick="script:... -
js 的document.forms[0].submit()把请求提交到哪里去了
2015-10-16 14:00:11提交到form里面的 action指向的地方了 document.forms[0].submit(); document.forms['exportServlet'].submit(); (1)document.forms:表示获取当前页面的所有表单 (2)document.forms[0]:... -
document.getElementById("").submit()作用
2019-11-27 15:50:14document.getElementById("").submit() 提交 作用和点击提交按钮是一样的。在表单里,一般都会指定表单的action: 表单会把数据提交到action设定的页面。如果没有action,默认是提交给当前的页面。 <script type=... -
document.getElementById()方法使用
2018-07-02 10:14:29document.getElementById使用 语法:oElement = document .getElementById ( sID ) 参数:sID――必选项。字符串 (Str -
js form action动态修改方法
2020-12-10 02:14:38一般比较简单的就是document.formName.action=”/dddd.do?ddd=”+str document.formName.submit(); 写成函数式的调用就是 代码如下:[removed] function checkaction(v){ if(v==0){ document.dbform.action=”index.... -
区别document.forms[0].usernames与document.getElementByName(usernames)
2012-01-31 11:17:18document.forms[0]在HTML页面中有一个form表单或者多个form表单的时候,都是返回一个NodeList类型的form数组 document.forms[0].usernames,这里的usernames可以是id的值,也可以是name的值,在这里这两个属性是等价...