Javascript 对象 #<HTMLFormElement> 的属性“提交”不是函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12540953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 10:39:43  来源:igfitidea点击:

Property 'submit' of object #<HTMLFormElement> is not a function

javascriptjqueryhtmlformssubmit

提问by Andrew Allen West

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

谁能向我解释这个错误是什么意思?对于这方面的任何帮助,我将不胜感激。

<form class="form" id="form" action="/mailer.php" method="post">

The Jquery code I'm using for it is this.

我使用的 Jquery 代码是这样的。

$('#form').submit();  

回答by xdazz

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

检查表单以查看是否有HTMLInputElementid 或 name 是submit

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

这将一个属性设置submitHTMLFormElement,所以submit不能被执行,其是在表格元件的原型函数。

Example:

例子:

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

js:

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.

jQuery 的.submit()方法会调用.submit()原始 dom 元素上的 ,因此会发生错误。

回答by ainokna

xdazzexplained the issue well.

xdazz 很好地解释了这个问题。

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

您可以使用HTMLFormElement的本机提交方法来解决问题:

HTMLFormElement.prototype.submit.call($('#form')[0]);

回答by Alex Reynolds

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

如果您有一个按钮或名称为 submit 或 id submit 的输入,我在 IE 中看到了错误。确保您的输入正确命名。这是一篇关于它的文章http://bugs.jquery.com/ticket/1414