使用 Javascript 提交表单
<form action="/?wpmlmethod=offsite&list=2&wpmlformid=" method="post">
...
</form>
我尝试过:
<script type="text/javascript">document.forms[0].submit();</script>
但没有成功。
<form action="/?wpmlmethod=offsite&list=2&wpmlformid=" method="post">
...
</form>
I tried:
<script type="text/javascript">document.forms[0].submit();</script>
But it didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该在某些
click
事件等上提交它,例如:更新:
正如您所说的表单已经填写,您想立即提交它,您可以尝试这个相反:
请注意
forms[0]
代表页面上的第一个表单,如果页面上有多个表单,则需要为其指定正确的索引,例如forms[ 1]
、表单[2]
等You should submit it on some
click
event, etc, for example:Update:
As you said form is already filled, you want to submit it straight away, you can try this instead:
Note that
forms[0]
represents the first form on your page, if there are more than one forms on your page, you will need to specify the correct index for it egforms[1]
,forms[2]
, etc也就是说,您可能不应该仅仅为了立即使用 JS 提交表单而加载页面。当您构建表单时,您应该已经在服务器上获得了所需的所有信息。它的设计有点糟糕,并且会破坏后退按钮。
submit
as this will clobber the submit method with a reference to that HTMLElementNode.That said, you probably shouldn't be loading a page just to instantly submit a form with JS in the first place. You should have already had all the information needed on the server when you built the form. It smells of bad design and can break the back button.