[英]Submit form with different submit buttons
I have a form that can be sent with different submit buttons: 我有一个可以使用不同的提交按钮发送的表单:
<form id="my_form">
<button type='submit' name='first_button'>
<button type='submit' name='second_button'>
<form>
I have created handler onclick via jquery for submit buttons which prevent default action, and doing some work but then I need to submit this form. 我已经通过jquery为提交按钮创建了处理程序onclick来阻止默认操作,并且做了一些工作,但是我需要提交此表单。
If I just simulate click on button - all actions triggered to onclick works once again. 如果我只是模拟单击按钮-触发onclick的所有操作将再次起作用。
If I use, the following code, it will just activate submit of first button: 如果使用以下代码,它将激活第一个按钮的提交:
$("#my_form").get(0).submit();
So how can I send the form differently according to the button that was clicked? 因此,如何根据单击的按钮以不同的方式发送表单?
Prevent default form submit. 阻止默认表单提交。
$("#my_form").submit(function(e){
return false;
});
// adding id
or class
to btns is better.. // add differnt event listners to buttons which will perform the submit action //将
id
或class
添加到btns更好。.//将不同的事件列表添加到将执行提交操作的按钮
$("[name='first_button']").on('click', function(){...});
$("[name='second_button']").on('click', function(){...});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.