如何使用两个按钮提交表单,其中一个按钮不能运行所有功能
我在这里看到了很多类似的问题,但找不到解决这一特定问题的问题。
我正在使用 jQuery 验证插件和表单插件。我想让一个提交按钮在提交完成后运行一项功能。但我希望另一个提交按钮跳过最后一个功能。关于如何执行此操作有什么建议吗?
代码如下:
$("#applicant-form").validate({
submitHandler: function(form) {
$(form).ajaxSubmit({
type: "POST",
//...
error: function() {alert("error!");},
success: function() {alert("success!");},
complete: function(e) {
//function not to run with second submit goes here
}
});
return false;
},
errorPlacement: function(error,element) {
return true;
},
//...
});
我希望第二个提交按钮在完整功能开始之前停止。
I have seen many similar questions on here but can't find one that addresses this particular issue.
I am using the jQuery Validation plugin and the form plugin. I want to have one submit button run a function after the submission is complete. But I want the other submit button to skip the last function. Any suggestions on how to do this?
Here's the code:
$("#applicant-form").validate({
submitHandler: function(form) {
$(form).ajaxSubmit({
type: "POST",
//...
error: function() {alert("error!");},
success: function() {alert("success!");},
complete: function(e) {
//function not to run with second submit goes here
}
});
return false;
},
errorPlacement: function(error,element) {
return true;
},
//...
});
I want the second submit button to stop right before the complete function starts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您可以利用
arguments.callee.caller.toString()
来确定哪个函数正在调用提交函数,如果它是特定的调用者,则运行该函数maybe you can take advantage of
arguments.callee.caller.toString()
to establish which function is calling the submit function and if it is a particular caller then you run the function尝试这样的事情:
$("#applicant-form").validate({
});
您可以识别按下了哪个提交按钮,然后在完整的函数中根据提交按钮的某些属性决定是否应该执行或跳过正文。
Try something like this:
$("#applicant-form").validate({
});
You can identify which submit button is pressed and then decide in the complete function whether the body shoudl be executed or skipped based on the some attribute of the submit button.