簡體   English   中英

一種形式的兩種動作

[英]Two actions with one form

我正在嘗試通過一次按鈕將表單提交到兩個不同的頁面。 目前,我正在嘗試將頁面提交到兩個隱藏的iframe,但是在提交表單時,第二項操作似乎不起作用。 這是我正在嘗試的編輯版本

<script language="javascript">
<!--
function OnButton1()
{
    document.Form1.action = "test1.php"    // First target
    document.Form1.target = "iframe1";    // Open in a iframe
    document.Form1.submit();        // Submit the page
    document.Form1.action = "test2.php"    // Second target
    document.Form1.target = "iframe2";    // Open in a iframe
    document.Form1.submit();        // Submit the page


}
-->
</script>


Submit Button
<input name="submit" src="test.png" type="image" id="submit" style="width: 238px; height: 92px; margin-top: 5px;" value="Submit" onclick="OnButton1();" />

I幀

<div style="visibility:hidden">
<iframe NAME="iframe1" WIDTH="40" HEIGHT="40"></iframe>
<iframe NAME="iframe2" WIDTH="40" HEIGHT="40"></iframe>
</div>

您不能同時提交2個表格。 我認為您必須更改策略以管理您的案件。

帕斯卡爾

嘗試一次

在javascript中添加此功能

   submitForms = function()
   {
          document.getElementById("formID1").submit();
          document.getElementById("formID2").submit();
   }

現在單一表格必須獲得2個ID

    <form id="formID1" target="iframe1">
    </form><iframe name="iframe1" style="display:none"></iframe>
    <form id="formID2" target="iframe2">
    </form><iframe name="iframe1" style="display:none"></iframe>
     <input type="button" value="Click Me!" onclick="submitForms()" />

檢查此URL以獲取DEMO http://plungjan.name/test/duosubmit.html

將您的輸入類型更改為button.I認為這可以解決您的問題。 您可以使用ajax來代替使用iframe。 如果您熟悉jQuery, 將對您有所幫助。

由於您的表單已提交,因此腳本不會進一步執行。 嘗試在第一個iframe加載時將表單提交給第二個操作。

window.iframe2.onload = function(){
    document.Form1.action = "test2.php"    // Second target
    document.Form1.target = "iframe2";    // Open in a iframe
    document.Form1.submit();  
}

您需要具有某種條件來防止窗體第一次加載時出現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM