.submit() called through javascript not working
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?
The submit
event is not supported with the live
function.
From the jQuery API:
In jQuery 1.3.x only the following JavaScript events (in addition to custom events) could be bound with .live(): click, dblclick, keydown, keypress, keyup, mousedown, mousemove, mouseout, mouseover, and mouseup. As of jQuery 1.4 the .live() method supports custom events as well as all JavaScript events. As of jQuery 1.4.1 even focus and blur work with live (mapping to the more appropriate, bubbling, events focusin and focusout). As of jQuery 1.4.1 the hover event can be specified (mapping to "mouseenter mouseleave").
Try calling submit() on the HTMLFormElement object:
$("#form")[0].submit();
Same results?
$("#form").trigger('submit');
???
精彩评论