我不得不尝试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;
}
不支持视差表单提交
因为表单提交意味着加载新的页面,所以浏览关闭所有现有的连接,就像你以前的表单提交。
<<p> 解决方案/strong>使用ajax
function my()
{
$.ajax({
url:document.schedule.action,
type:'post',
data:$(document.schedule).serialize()
});
return true;
}
submit()将以正常方式提交表单,从而在提交另一个/第二个表单之前重新加载页面。要做您想做的事情,请使用AjaxjQuery 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
});
}
在我看来,你不再需要两个表单,只需要一个。