[英]Is it possible how to two forms submit by one button and then two forms perform two different actions?
我必须尝试使用JavaScript。但是它仅执行一种表单操作。请说明如何在同一页面中使用两种表单对一个按钮进行操作。
我必须使用以下代码:
function my() { document.schedule.action = "firstaction"; document.schedule.target = "_blank"; document.schedule.submit(); return true; } function my1() { document.consultant.action = "secondaction"; document.consultant.target = "_blank"; document.consultant.submit(); return true; }
无法提交视差表格
由于表单提交意味着要加载新页面,因此请浏览并关闭所有现有连接,例如您以前的表单提交。
解
使用ajax
function my()
{
$.ajax({
url:document.schedule.action,
type:'post',
data:$(document.schedule).serialize()
});
return true;
}
Submit()将以正常方式提交表单,从而在提交其他/第二个表单之前重新加载页面。 使用Ajax来做您想做的事情jQuery Ajax示例:
$("#form1").submit(function(e){
e.preventDefault();
$.post("functions.php", {key1:"value1", key2:"value2"}, function(data){
//submit the second form here using the same $.post method
});
});
解决方案就是Ajax。
您可以执行以下操作:
<form class="myform">
<!-- form 1 fields -->
</form>
<form class="myform">
<!-- form 2 fields -->
</form>
并使用JQuery
$('.myform').sumit(function(e)) {
e.preventDefault();
// FORM VALIDATION
// Form 1 function
$.ajax({
url: "action1",
}).success(function() {
// DO SOMETHING
});
// Form 2 function
$.ajax({
url: "action2",
}).success(function() {
// DO SOMETHING
});
}
顺便说一句,我认为您不再需要两种形式,而只需一种形式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.