我在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();
});
答案 0 :(得分: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>
我希望这会有所帮助。