JavaScript setInterval调用form.submit

时间:2015-09-06 08:30:58

标签: javascript setinterval

我需要根据计时器的时间提交表单。它不是调用表单提交。请建议我

我在document.ready中调用starttimer

$(document).ready(function(){
    var duration = 60*20;
    display = $('#timer');
    startTimer(duration, display);

    $.fn.disableSelection = function() {
    return this
             .attr('unselectable', 'on')
             .css('user-select', 'none')
             .on('selectstart', false);
    };

    $("#question_container").disableSelection();
});

function startTimer(duration, display) {
    var timer = duration, minutes, seconds;
    setInterval(function () 
    {
        minutes = parseInt(timer / 60, 10);
        seconds = parseInt(timer % 60, 10);

        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        display.text(minutes + ":" + seconds);

        if (--timer < 0) {
            $("#questionform").submit();
        }
    }, 1000);
}
setInterval ( "autosubmit()", 5000000 );
function autosubmit()
{
document.theFormName.submit;
}

2 个答案:

答案 0 :(得分:2)

document.theFormName.submit;没有做任何事情。它只是访问一个函数,然后忽略它。

如果你想打电话,那你实际上必须打电话给它:

document.theFormName.submit();

答案 1 :(得分:-1)

只需更改

setInterval ( "autosubmit()", 5000000 );

setInterval ( autosubmit, 5000000 );
  

这是更多细节   https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval