2017-04-11 56 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> 
相關問題