2016-09-17 71 views
-3

我在3种不同的页面上有3种形式,提交按钮在第3页上。如何通过点击提交按钮同时提交所有3种表格?有没有在JavaScript或jQuery的任何解决方案?如何一次提交3种不同页面的3种形式

页面-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(); 
}); 
+0

你尝试过什么吗?你能证明你做了什么吗? – JeetDaloneboy

+0

我已经创建了一个单独的js文件submit.js,并且在那里我写了代码, $(document).click(“#submit”,function(){(“#firstForm”)。submit(); $(“#secondtForm”)。submit(); $(“#thirdForm”)。submit(); }); – tech007

+0

尝试使用hiden html iframe。 – JeetDaloneboy

回答

0

你在这里有意尝试创造的东西被称为向导 - 一个更大的表单,它被分解为不同的部分。一种常见的方法是使用服务器端语言将第一页的表单域的值作为隐藏的输入元素写入第二页。例如:

<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> 

我希望这有助于。