jQuery doesn't submit a form

前端 未结 4 1724
借酒劲吻你
借酒劲吻你 2020-12-06 01:02

I have the following HTML code:





        
相关标签:
4条回答
  • 2020-12-06 01:49

    I think you fire the submit event before the DOM is actually loaded, because if I try it, this code works:

    $(document).ready(function(){
    
        // Submit handler, to prove everything works fine
        $('#umfrageForm').submit(function(){
            alert('hi');
            return false;
        });
    
        // Fire the submit event
        $('#umfrageForm').submit(); // alerts 'hi'
    });
    

    See: jsFiddle

    0 讨论(0)
  • 2020-12-06 01:51

    yes when you have input elements with the name "submit" you will find the $('#formID').submit() to not to behave as it is expected. Just replace the input field name (may be the submit button) to something more relevant.

    I know this post is old one, just had the same problem for me and thought I should post my findings.

    0 讨论(0)
  • 2020-12-06 01:53

    I had once similar problem. Your code should work if you include Java-script file as you show. However, I suspect your code is a part of a bigger html-document. The problem arises when you download the body part of your html-document into another html-document without including Java-script-functions in sub-document (since they are included in the parent-document). Then it will not work. You have to include Java-script file also in sub-document.

    0 讨论(0)
  • 2020-12-06 02:06

    You have a field named submit, this clobbers the submit method of the form (with a reference to the DOM node for the field) that jQuery depends on in its own submit method.

    Rename it.

    0 讨论(0)
提交回复
热议问题