【问题标题】:Can I submit two forms with one button我可以用一个按钮提交两个表单吗
【发布时间】:2018-05-03 14:29:35
【问题描述】:

比如说我有这两种形式

<form method="post" action="/lorum/ipsum/dolor/sit/amet">
<!-- Some stuff --> 
</form>
<form method="post" action="some/other/location/here">
<!-- Some stuff --> 
</form>


<button> </button> <!-- this is going to submitboth forms 

我希望这是有道理的

【问题讨论】:

  • 您可以编写javascript来处理按钮上的click并手动发出请求。
  • 你为什么要这样做?你想达到什么目的?

标签: javascript html css


【解决方案1】:

类似的工作:

document.getElementById("submit").onclick = function() {
  document.getElementById("form1").submit();
  document.getElementById("form2").submit();
}
<form id="form1" method="post" action="/lorum/ipsum/dolor/sit/amet">
  <!-- Some stuff -->
</form>
<form id="form2" method="post" action="some/other/location/here">
  <!-- Some stuff -->
</form>

<button id="submit">Submit forms</button>

我不知道如何测试它,但如果我发现我会尝试更新我的 sn-p。 :)

希望对你有帮助。

【讨论】:

    【解决方案2】:

    此代码有效。

    <SCRIPT LANGUAGE="JavaScript">
    
    <!--
    
    function SubmitBoth()
    
    {
    
    document.frm1.submit();
    document.frm2.submit();
    }
    //-->
    </SCRIPT>
    
    <form name="frm1" target="formresponse1" action="send1.php" method="post">
    </FORM>
    
    <form name="frm2" target="formresponse2" action="send2.php" method="post">
    </FORM>
    
    
    <INPUT TYPE="button" value="SubmitBoth" onClick="SubmitBoth()">
    
    <iframe name='formresponse1' width='300' height='200'></frame>
    <iframe name='formresponse2' width='300' height='200'></frame>
    

    也许别人会整理一下!

    【讨论】:

    • 前段时间已经接受了一个正确且更简洁的答案。请仅在提供更多见解时提交其他答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-29
    • 1970-01-01
    • 1970-01-01
    • 2010-10-07
    相关资源
    最近更新 更多