倒计时器,在页面刷新时不复位

时间:2010-11-13 16:50:44

标签: jsf timer

如何在JSF中创建倒计时器?我不希望刷新页面时重置计时器。

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

您只需使用此脚本

即可
 var seconds = readCookie('countdown') || 60;
        alert(seconds);
        function secondPassed()
        {
            seconds--;
            var minutes = parseInt(seconds / 60);
            var remainingSeconds = parseInt(seconds % 60);
            if (remainingSeconds < 10) {
                remainingSeconds = "0" + parseInt(remainingSeconds);
            }
            document.getElementById('countdown').innerHTML = minutes + " mins : " + remainingSeconds + " secs";
           if (parseInt(seconds) === 0)
            {
                alert("Time is over");
                clearInterval(countdownTimer);
                document.getElementById('countdown').innerHTML = "Time is Over";
                document.forms["myForm"].submit();
                document.location.href = "examresult.jsp";
            }
        }
        var countdownTimer = setInterval(function() {
            secondPassed();
            if (seconds === 0) {
                eraseCookie(seconds);
            } else {
                createCookie(seconds, seconds, 7);
            }
        }, 1000);