TypeError:document.getElementById(...).submit不是一个函数 [英] TypeError: document.getElementById(...).submit is not a function
问题描述
我遇到一个错误,找不到解决方案,也不必使用jQuery.我没有任何以名称提交的div
I'm having an error that I can't find the solution and I don't have to use jQuery; I don't have any div with submit as name
我的代码是
<!DOCTYPE html>
<html>
<head>
<script>
function formSubmit()
{
document.getElementById('web').submit();
}
</script>
</head>
<body>
<form action="class003.php" id="g_form" method="POST">
<input type="text" name="f1" value="">
</form>
<div id="web" onclick="formSubmit()">click</div>
</body>
</html>
在chrom上出现此错误
on chrom I'm getting this error
未捕获的TypeError:document.querySelector(...).submit不是功能在formSubmit(test2.html:8)在HTMLDivElement.onclick(test2.html:19)
Uncaught TypeError: document.querySelector(...).submit is not a function at formSubmit (test2.html:8) at HTMLDivElement.onclick (test2.html:19)
在Firefox上出现相同的错误
on Firefox the same error
TypeError:document.getElementById(...).submit不是一个函数[学习更多]
TypeError: document.getElementById(...).submit is not a function[Learn More]
推荐答案
您需要提交 form
而不是 div
制作
document.getElementById('g_form').submit();
这篇关于TypeError:document.getElementById(...).submit不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!