如何从表单提交事件中获取导致提交的按钮? [英] How can I get the button that caused the submit from the form submit event?
本文介绍了如何从表单提交事件中获取导致提交的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找到触发表单提交的提交按钮的值
I'm trying to find the value of the submit button that triggered the form to submit
$("form").submit(function() {
});
我可能会为每个按钮触发 $("input[type=submit]").click() 事件并设置一些变量,但这似乎不如在提交时将按钮从表单中拉出那样优雅.
I could possibly fire a $("input[type=submit]").click() event for each button and set some variable, but that seems less elegant than some how pulling the button off of the the form on submit.
推荐答案
我实现了这个,我想它会做.
I implemented this and I suppose it will do.
$(document).ready(function() {
$("form").submit(function() {
var val = $("input[type=submit][clicked=true]").val()
// DO WORK
});
这是设置它的提交按钮事件
and this is the submit button event that sets it up
$("form input[type=submit]").click(function() {
$("input[type=submit]", $(this).parents("form")).removeAttr("clicked");
$(this).attr("clicked", "true");
});
感谢您的回复,但这并不是非常不雅......
Thanks for the responses, but this isn't terribly inelegant...
这篇关于如何从表单提交事件中获取导致提交的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文