javascript submit() 不是一个函数?

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

javascript submit() is not a function?

javascriptjqueryformsfunctionsubmit

提问by Pinkie

Possible Duplicate:
submit is not a function in javascript

可能重复:
提交不是 javascript 中的函数

Why is the following basic javascript function giving me an error document.getElementById("form").submit is not a function.

为什么下面的基本 javascript 函数给我一个错误document.getElementById("form").submit is not a function

The only thing i have on a page is a form and this javascript function. I want he form to auto submit when page is accessed.

我在页面上唯一的东西是一个表单和这个 javascript 函数。我希望他的表单在访问页面时自动提交。

<script>
 window.onload = function(){
 document.getElementById('form').submit();
}
</script>

回答by Naftali aka Neal

Make sure that there is no name="submit"or id="submit"in the form

确保没有name="submit"id="submit"在表格中

回答by duri

This is probably because the form contains input with name=submit; then the submitproperty contains object of the element. Rename it or use

这可能是因为表单包含 name=submit; 的输入;然后该submit属性包含元素的对象。重命名或使用

document.createElement('form').submit.call(document.getElementById('form'));