Property 'submit' of object # is not a function

前端 未结 3 1167
别跟我提以往
别跟我提以往 2020-11-27 05:29

Can anyone explain to me what this error means? I would appreciate it a lot for any kindof help with this.

相关标签:
3条回答
  • 2020-11-27 05:54

    Check the form to see whether there is a HTMLInputElement with id or name is submit.

    This will set a property submit to the HTMLFormElement, so the submit function which is in the prototype of the form element can't be executed.

    Example:

    <form class="form" id="form" action="/mailer.php" method="post">
        ​<input type="button" name="submit" value="go"/>
    </form>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
    

    js:

    ​console.log($("#form")[0].submit)​;​  // will be the button element, not the submit function.
    

    jQuery's .submit() method will call the .submit() on the original dom element, so the error will happen.

    0 讨论(0)
  • 2020-11-27 05:59

    xdazz explained the issue well.

    You can use a native submit method of HTMLFormElement to work around a problem:

    HTMLFormElement.prototype.submit.call($('#form')[0]);
    
    0 讨论(0)
  • 2020-11-27 06:03

    If you have a button or input with the name submit or id submit, I have seen errors in IE. Make sure your inputs are correctly named. Here's an article on it http://bugs.jquery.com/ticket/1414

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