2017-04-11 5 views
0

解決策が見つからないというエラーがあり、jQueryを使用する必要はありません。名前として提出すると、私はすべてのdiv要素を持っていないTypeError:document.getElementById(...)。submitが関数ではありません

私のコードはCHROM上

<!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>

は、私は、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

あなたがいないdiv

はそれが

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

あなたがIDあなたのdivを使用して行いますが、フォームを送信するためにあなたがあなたのFormのIDを指定する必要がformを提出する必要があります要素

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

NGEそれはここで

<!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> 
関連する問題