javascript倒计时器与cookie

时间:2017-10-27 13:18:57

标签: javascript jquery cookies counter countdown

我有这个代码 它在页面的每次刷新中都会设置倒计时器

我需要添加cookie,花时间和完成提交表格后开始时间agine

如何添加cookie的代码

var time = $('#time').val();
document.getElementById('timer').innerHTML = time + ":" + 00;
startTimer();

function startTimer() {
    var presentTime = document.getElementById('timer').innerHTML;
    var timeArray = presentTime.split(/[:]+/);
    var m = timeArray[0];
    var s = checkSecond((timeArray[1] - 1));
    if (s == 59) { m = m - 1 }

    if (m == 0 && s == 0) {
        $('#saveQuestion').submit();
    }

    document.getElementById('timer').innerHTML =
        m + ":" + s;

    setTimeout(startTimer, 1000);
}

function checkSecond(sec) {
    if (sec < 10 && sec >= 0) { sec = "0" + sec };
    if (sec < 0) { sec = "59" };
    return sec;
}

0 个答案:

没有答案