参见英文答案 >
How can I get the button that caused the submit from the form submit event?12个
我从一个没有写的程序中打开一些表单.为此,我想出了这个聪明的解决方案:
我从一个没有写的程序中打开一些表单.为此,我想出了这个聪明的解决方案:
jQuery("form").submit(function(event) { // get some values from elements on the page: var the_form = jQuery(this); var data = the_form.serialize(); var url = the_form.attr( 'action' ); var button = event.originalEvent.explicitOriginalTarget; data = data + "&" + button.name + "=" + button.value; // Send the data using post and put the results in a div jQuery.post( url,data,function() { //Do something crazy }); // stop form from submitting normally if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; } });
哪个工作完美.我走开欣喜.问题是,我无意中使用Mozilla / Gecko属性来确定点击了哪个按钮. (event.originalEvent.explicitOriginalTarget)这意味着这只适用于Firefox. 原文链接:https://www.f2er.com/jquery/180108.html