时间到时如何调用提交动作按钮

我想自动使用javascript单击提交表单时遇到问题,因此在这种情况下,我想在时间到了时提交按钮Validate Answer,我的代码有问题吗? 这是我称为提交按钮的代码

document.getElementById('onResult').submit();

下面是完整的代码

<script type="text/javascript">
            var upgradeTime = @Model.Duration;
            var seconds = upgradeTime;
            function timer() {
                var days = Math.floor(seconds / 24 / 60 / 60);
                var hoursLeft = Math.floor((seconds) - (days * 86400));
                var hours = Math.floor(hoursLeft / 3600);
                var minutesLeft = Math.floor((hoursLeft) - (hours * 3600));
                var minutes = Math.floor(minutesLeft / 60);
                var remainingSeconds = seconds % 60;
                function pad(n) {
                    return (n < 10 ? "0" + n : n);
                }
                document.getElementById('countdown').innerHTML = pad(hours) + ":" + pad(minutes) + ":" + pad(remainingSeconds);
                if (seconds == 0) {
                    clearInterval(countdownTimer);
                    //alert("Your Test Time Has Expire...!");]
                    document.getElementById('onResult').submit();
                    document.getElementById('countdown').innerHTML = "Completed";
                } else {
                    seconds--;
                }
            }
            var countdownTimer = setInterval('timer()', 1000);
    </script>
    <span id="countdown" class="timer"></span>
    @using (Html.BeginForm("CollectQuiz", "Exam"))
    {
        @Html.HiddenFor(model => @Model.Id, new { htmlAttributes = new { @class = "form-control" } })
        for (var i = 0; i < Model.Soals.Count(); i++)
        {
            <div class="modal-content">
                <div class="modal-body">
                    <p>@Model.Soals[i].Id @Model.Soals[i].Question</p>

                    @Html.HiddenFor(model => @Model.Soals[i].Id, new { htmlAttributes = new { @class = "form-control" } })

                    @for (var j = 0; j < Model.Soals[i].Choices.Count(); j++)
                    {
                        <p>
                            @Html.RadioButtonFor(m => m.Soals[i].SelectedAnswerId, Model.Soals[i].Choices[j].Id, new { id = "Question" + i.ToString() + "Answer" + j.ToString() })
                            <label for="Question@(i)Answer@(j)">@Model.Soals[i].Choices[j].Id @Model.Soals[i].Choices[j].Name</label>
                        </p>
                    }
                    <button class="btn btn-sm text-info"><b>Kesulitan:  @Model.Soals[i].Difficulty</b> </button>
                </div>
            </div>
        }
        <input id="onResult" type="submit" value="Validate Answers" />
    }

我有错误 Document.getElementById(...)。submit不是一个函数

评论