javascript TypeError: '[object HTMLInputElement]' 不是 jQuery form.submit() 中的函数(评估 'elem[ type ]()')

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8672914/
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-10-26 04:11:10  来源:igfitidea点击:

TypeError: '[object HTMLInputElement]' is not a function (evaluating 'elem[ type ]()') in jQuery form.submit()

javascriptjqueryhtmlformssubmit

提问by juminoz

Has never run into this issue? I'm getting this error in the latest release of jQuery. I tried with version 1.6.2 and there is no issue.

有没有遇到过这个问题?我在最新版本的 jQuery 中收到此错误。我试过 1.6.2 版,没有问题。

TypeError: '[object HTMLInputElement]' is not a function (evaluating 'elem[ type ]()')

line 3175

Has anything changed that we should be aware of?

有什么变化是我们应该注意的吗?

Thanks, Hyman

谢谢,Hyman

回答by Shiplu Mokaddim

This usually happens if any of your inputtag's name is submit. For example,

如果您input的任何标签名称是submit. 例如,

<form id="frm">
    <input type="submit" name="submit" value="Post" />
</form>

On the above code, document.getElementById("frm").submitrepresents the inputelement. When you apply ()to submitIt shows this error.

在上面的代码中,document.getElementById("frm").submit代表input元素。当您申请()submit它会显示此错误。

回答by Peter Gluck

I have found that this error will occur when using the onclickattribute to call a JavaScript function with the same name as eitherthe idornameattributes on an inputelement:

我发现,使用时会出现此错误onclick属性来访问具有相同名称的JavaScript函数为任意id或者name一个属性上的input元素:

<input id='foo' name='fooName' onclick='foo();'> <!-- BAD: id matches function -->

<input id='fooId' name='foo' onclick='foo();'> <!-- BAD: name matches function -->

<input id='fooId' name='fooName' onclick='foo();'> <!-- WORKS! -->

This behavior occurs irrespective of input type.

无论输入类型如何,都会发生此行为。

回答by Chris

I hade a similar issue with safari recently on a bit of javascript to submit a form. Turned out to be due to the submit input element having the name="submit", which was conflicting causing it to return it as not being a function.

我最近在 safari 上遇到了类似的问题,使用了一些 javascript 来提交表单。原来是由于提交输入元素具有name="submit",这是冲突导致它返回它作为不是一个函数。