通过 javascript 调用的 .submit() 不起作用
当我通过 javascript 调用时,我无法确定是什么原因导致我的表单未提交
$('#form').submit();
(但当我单击提交按钮时提交正常)。因此,我添加这段代码进行测试:
$('#form').live('submit', function()
{
alert('submitting form');
return true;
});
现在,当我单击提交按钮时,将显示警报,然后提交表单。当我
$('#form').submit();
通过 javascript 调用:时,会显示警报,但表单不会提交。现在我通过 ajax 将表单拉到模式窗口上,所以不确定这是否与它有关。有谁知道可能导致此问题的原因是什么?
I was having trouble determining what was cause my form to not submit when I called
$('#form').submit();
through javascript (but submitted fine when I clicked on the submit button). So I add this piece of code for testing:
$('#form').live('submit', function()
{
alert('submitting form');
return true;
});
Now when I click the submit button, the alert displays and then the form submits. When I call:
$('#form').submit();
through javascript, the alert displays however the form does not submit. Now I am pulling the form through ajax onto a modal window so not sure if that has anything to do with it. Anyone know what might be causing this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试在 HTMLFormElement 对象上调用 Submit():
结果相同吗?
Try calling submit() on the HTMLFormElement object:
Same results?
???
???
live
函数不支持submit
事件。从 jQuery API:
The
submit
event is not supported with thelive
function.From the jQuery API: