![](/img/trans.png)
[英]Chrome - how to submit by javascript a form having input name=submit?
[英]How to do javascript form submit in chrome
嗨,我正在使用JavaScript,jQuery和MVC应用程序。
document.forms['shipform'].submit();
在这里,我提交这样的表格。
在此页面中,我总共有三种形式。
这是我的表格:
<% using (Html.BeginForm("OrderShipments", "Shipments", FormMethod.Post, new { @id = "shipform" })) // Creates <form>
{%>
<input type="hidden" id="Hiddenid" name="orderId" />
<input type="submit" value="book" style="display: none" />
<%} %>
它不适用于Chrome,但适用于Firefox。
document.forms[0].submit();
如果我使用forms[0]
,如果我在一个页面中有三个表单,将采用哪种形式?
您拥有的代码将根据其名称提交表单:
document.forms['shipform'].submit();
^^^ form name not ID
如果要通过表单ID提交表单,请使用:
document.getElementById('shipform').submit();
或jQuery:
$('#shipform').submit();
如果您使用的是jQuery,则可以执行以下操作:
$('#shipform').submit();
假设代码输出一个ID="shipform"
的表单
<form id="shipform"></form>
您可以使用getElementById()
“获取”表单,然后submit()
其submit()
:
document.getElementById("shipform").submit();
这应该以您的表格发送。
(假设{ @id = "shipform" }
将表单上的id
设置为"shipform"
)
如果您使用forms[0]
,则它应使用页面上的“第一个”表单,因此在html中首先加载的表单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.