这个问题之前在SO上被问过但没有成功,也许是不同的场景
这是我的表单
<form id="testSubmit" method="post" action="submit.php">
<!--The value of following field will be obtained when user submits test or time runs out -->
<input type="hidden" name="user_answer" id="user_answer" value=""/>
<input type="submit" id="submit" style="padding:5px;" value="Submit"/>
</form>
这是我的 Javascript 和 jQuery 代码
<script type="text/javascript">
$('document').ready(function()
{
//pick up the options selected by the student and populate #userAnswer
$('#testSubmit').submit(function()
{
var string='';
$('.question').each(function ()
{
string += $(this).find('input[type="radio"]:checked').length ? $(this).find('input:checked').val() : 'z';
});
$('#user_answer').val(string);
});
//timer for countdown and to submit the form
var delay=5;
function countdown()
{
setTimeout(countdown,1000);
$('#timer').html("Time"+delay);
delay--;
if(delay<0)
{
$("#testSubmit").submit();
delay=0;
}
}
countdown();
});
</script>
但这不会提交并给出错误 e[h] is not a function
;
我也试过document.getElementById("testSubmit").submit()
并给出错误 document.getElementById("testSubmit").submit() is not a function
.
与 document.forms[0].submit
相同的错误
编辑
我放了一个 alert('Hello');
在定时器内部并且它工作。所以定时器工作正常。问题是一旦时间达到零,就会出现错误。
最佳答案
“但这不会提交并给出错误 e[h] 不是函数;”
将 id="submit"更改为其他内容。原因是,如果您有一个 ID 为 submit 的输入元素,它将使用 HTMLInputElement 为表单设置一个 submit 属性。因此,您无法在 HTMLFormElement 上调用 .submit 方法。
关于javascript - jQuery 表单超时不提交 - e[h] 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21577902/