jquery .submit(handler) 似乎没有检测表单提交
所以我试图使用 jquery 拦截 javascript 表单提交,但遇到了一些问题。我将 Spring 放在标签中,因为我想知道问题是否可能是因为我使用的是 spring form:form 标签,而不仅仅是直接的 html 表单。基本上,处理程序似乎完全被忽略,无论如何提交都会继续进行。
相关代码如下:
function submitForm(functionName){
var form = document.getElementById("evalAdminForm");
//does some stuff
form.submit();
}
$('form').submit(function(){
alert("SUBMITDETECTED");
});
<form:form commandName="evaluation" id="evalAdminForm" name="evalAdminForm" method="post">
//the form is in here
</form:form>
谢谢!
so I'm trying to intercept a javascript form submission using jquery, and having some issues. I put Spring in the tags because I wonder if the issue could be that I'm using a spring form:form tag, rather than just a straight html form. Basically, the handler seems to be totally ignored, with the submission going on regardless.
The relevant code is as follows:
function submitForm(functionName){
var form = document.getElementById("evalAdminForm");
//does some stuff
form.submit();
}
$('form').submit(function(){
alert("SUBMITDETECTED");
});
<form:form commandName="evaluation" id="evalAdminForm" name="evalAdminForm" method="post">
//the form is in here
</form:form>
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
提交事件在手动提交表单时触发,而不是响应调用提交方法的 JavaScript。
如果您要使用 JS 触发表单提交(而且几乎没有任何时候这样做比使用提交按钮更好),那么您需要手动触发您想要同时运行的任何其他功能。
Submit events fire when forms are submitted manually, not in response to JavaScript calling the submit method.
If you are going to trigger form submission using JS (and there is almost never a time when doing so is better than having a submit button) then you need to manually fire any other functions you want to run at the same time.