JS - 如何提交表单onclick并发送提交按钮 [英] JS - How to submit form onclick and send submit button

查看:780
本文介绍了JS - 如何提交表单onclick并发送提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < form>< p> 
< input name =datatype =text>
< input type =submitname =sendid =send-buttonstyle =display:none>
< / form>

按钮#发送按钮可见,我需要发送整个形式到服务器。这意味着我收到了 $ data $发送(两者)。 现在我得到 $ data



有什么想法?

解决方案

您可以使用JavaScript表单方法

 < button onclick =document.forms [0] .submit()> ;< /按钮> 

如果您在文档中有多个表单,则将ID设置为表单

 < form id =form1> 
< input name =datatype =text>
< input type =submitname =sendid =send-buttonstyle =display:none>
< / form>
< button onclick =document.getElementById(form1)。submit()>< / button>


I need to submit form by button which is out of scope of the form by JavaSript.

<form>
  <input name="data" type="text">
  <input type="submit" name="send" id="send-button" style="display: none">
</form>

<button onclick="$('#send-button').click() || .submit()"></button>

The button #send-button is visible and I need to send whole form to server. It means I receive $data and $send (both).

Now I am getting just the $data.

Any idea?

解决方案

You can do with javascript form method

<button onclick="document.forms[0].submit()"></button>

if you have multiple forms in the document then set id to the form

<form id="form1">
  <input name="data" type="text">
  <input type="submit" name="send" id="send-button" style="display: none">
</form>
<button onclick="document.getElementById("form1").submit()"></button>

这篇关于JS - 如何提交表单onclick并发送提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆