如何在JSF中创建倒计时器?我不希望刷新页面时重置计时器。
答案 0 :(得分:1)
You can simply use Java Script for it.
或
You can use RichFaces a4j:poll and poll count data from server where your timer will be running
答案 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);