取决于按下按钮的不同形式的行动 [英] Different form ACTION depending on button pressed

查看:84
本文介绍了取决于按下按钮的不同形式的行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如,如果表单可能由不同的PHP文件处理,如果我按下按钮A或按钮B.



我该怎么做?

谢谢!

解决方案

在按钮中,您可以设置表单的动作,使用它的 form 属性,例如在按钮a上:

  this.form.action =fileA.php; 

另一方面:

  this.form.action =fileB.php; 

您可以在外部操作,如下所示:

  document.getElementById(buttonA)。onclick = function(){
document.getElementById(myForm)。action =fileA.php;
};

或者如果您使用的是类似jQuery的库:



$ $ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ attr('action','fileA.php');
});
});


I have a form and I would like the ACTION field to be different depending on the button pressed.

For instance the form might get processed by different PHP files if I press button A or button B.

How can I do this?

Thanks!

解决方案

In your buttons you can just set the form's action, using it's form property, for example on button a:

this.form.action = "fileA.php";

On the other:

this.form.action = "fileB.php";

You can rig this up externally, like this:

document.getElementById("buttonA").onclick = function() { 
  document.getElementById("myForm").action = "fileA.php";
};

Or if you're using a library like jQuery:

$(function() {
  $("#buttonA").click(function() {
    $(this).closest("form").attr('action', 'fileA.php');
  });
});

这篇关于取决于按下按钮的不同形式的行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆