2017-04-11 55 views
0

我有一个错误,我无法找到解决方案,我没有使用jQuery;我没有任何分度,提交姓名类型错误:的document.getElementById(...)提交不是一个函数

我的代码是

<!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我在Firefox相同收到此错误

Uncaught TypeError: document.querySelector(...).submit is not a function at formSubmit (test2.html:8) at HTMLDivElement.onclick (test2.html:19)

错误

TypeError: document.getElementById(...).submit is not a function[Learn More]

回答

3

您输入错误元素的id。它应该是g_form

function formSubmit()  
{  
    document.getElementById('g_form').submit();  
} 
3

您需要提交form不是div

让它

document.getElementById('g_form').submit();  
1

您使用ID您div但提交表单你需要指定你Form的ID元素

所以才查NGE的

function formSubmit()  
{  
    document.getElementById('g_form').submit(); // Change the Id here 
} 

希望此举能帮助

<!DOCTYPE html>  
 
<html>  
 
<head>  
 
<script>  
 
function formSubmit()  
 
{  
 
    document.getElementById('g_form').submit(); // Change the Id here 
 
}  
 
</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>

1

这里是您的解决方案。

<!DOCTYPE html>  
<html>  
<head>  
<script>  
function formSubmit()  
{  
    document.forms['g_form'].submit(); 
}  
</script>  
</head>  
<body>  

<form action="class003.php" id="g_form" name="g_form" method="POST"> 
    <input type="text" name="f1" value=""> 

</form> 
<div class="button1" onClick="formSubmit();">Click</div> 
</body>  
</html> 
相关问题