开发者

jQuery form submitting

i have several forms within my website that each have the submit button as a href.

all my a's are caught through jQuery

$("a").live("click", function() {

inside that area there is a big switch statement that depending on the id of the a different actions will be taken. For all formSubmit ids, the parent is retrieved.

case "formSubmit": a.parents("form:first").submit();

i want to catch all the forms, so i try this...

$("form").live("submit", function() {

But when i execute that, i test it out with putting the forms action as some alert so i know if its executing its own action or i am ove开发者_运维知识库rriding it. I am not overriding it. The form is also added dynamically with jQuery doing a $.post call, then taking the output and filling the main content area.

If i use ...

$("form").submit(function() {

The forms will NOT be captured either. Not the forms that were during the creation of the document or the ones added during the users time on the site. Any suggestsions? (Had to edit due to super poor english skills!).


jQuery's .submit() simply triggers the submit event. To actually submit the form, you want the DOM's .submit():

a.parents("form:first")[0].submit();

Side note: use .closest("form") rather than .parents("form:first")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜