【问题标题】:How to submit 3 forms of 3 diffrent pages at once如何一次提交 3 个不同页面的 3 个表单
【发布时间】:2016-09-18 04:10:50
【问题描述】:

我在 3 个不同的页面中有 3 个表单,提交按钮位于第 3 页。如何通过单击提交按钮同时提交所有 3 个表单? javascript或jquery有什么解决方案吗?

第 1 页

<script src="home/submit.js" type="text/javascript"></script> 
<form id="firstForm">
  <input type="checkbox" name="answ1" value="answ1" autocomplete="off"/>
</form>

第 2 页

<script src="home/submit.js" type="text/javascript"></script> 
<form id="secondForm">
  <input type="checkbox" name="answ2" value="answ2" autocomplete="off"/>
  <input type="checkbox" name="answ3" value="answ3" autocomplete="off"/>
  <input type="checkbox" name="answ4" value="answ4" autocomplete="off"/>
</form>

第 3 页

<script src="home/submit.js" type="text/javascript"></script> 
<form id="ThirdForm">
  <input type="checkbox" name="answ5" value="answ5" autocomplete="off"/>
  <input type="checkbox" name="answ6" value="answ6" autocomplete="off"/>
  <input type="checkbox" name="answ7" value="answ7" autocomplete="off"/>
  <button id="submitt" type="submit">submit</button>
</form>

在 submit.js 中我写过

$(document).click("#submit",function(){
  $("#firstForm").submit();
  $("#secondForm").submit();
  $("#thirdForm").submit();
});

【问题讨论】:

  • 您尝试过什么吗?你能展示你做了什么吗?
  • 我创建了一个单独的 js 文件 submit.js 并在那里编写了代码 $(document).click("#submit",function(){ $("#firstForm")。提交(); $("#secondtForm").submit(); $("#thirdForm").submit(); });
  • 尝试使用隐藏的html iframe。
  • 把所有数据放到同一个表格中...如果需要将部分数据发送到另一个服务器,使用curl

标签: javascript jquery ajax html


【解决方案1】:

您在此处有效地尝试创建的内容称为向导 - 一个更大的表单,被分解为多个单独的部分。一种常见的方法是使用服务器端语言将第一页的表单字段的值作为隐藏输入元素写入第二页。例如:

<script src="home/submit.js" type="text/javascript"></script> 
<form id="secondForm">
  <!-- this is the submission from the first page, and could be generated in a server-side scripting language -->
  <input type="hidden" name="answ1" value="ANSWER" />
  <input type="checkbox" name="answ2" value="answ2" autocomplete="off"/>
  <input type="checkbox" name="answ3" value="answ3" autocomplete="off"/>
  <input type="checkbox" name="answ4" value="answ4" autocomplete="off"/>
</form>

我希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    • 2012-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多