我們對我們網站的在線問答部分,它有一個JavaScript代碼,算我們的測試人員參與一個特定的測試時間:本計數進位和倒數計時器在javascript
526代碼是指從測驗通過秒數開始
document.writeln("<span id=\"time_online1\"></span>");
zi_inceput1 = new Date();
ceas_start1 = zi_inceput1.getTime();
function initStopwatch1() {
var timp_pe_pag1 = new Date();
return ((timp_pe_pag1.getTime() + (1000 * 526) - ceas_start1)/1000);
}
var time = 5 * 60;
function getSecs1() {
var tSecs1 = Math.round(initStopwatch1());
var iSecs1 = time - tSecs1 % 60;
var tMins1 = Math.round(iSecs1/60);
var iMins1 = time - tMins1 % 60;
var sSecs1 = iSecs1 % 60;
var sMins1 = iMins1 % 60;
if (sMins1 === '0' && sSecs1 === '0') {
alert('time is up and you can not continue, the test is submited.');
document.getElementById('time_online1').innerHTML = "times up";
document.qs.submit();
} else {
document.getElementById('time_online1').innerHTML = sMins1 + ":" + sSecs1;
window.setTimeout('getSecs1()', 1000);
}
}
window.setTimeout('getSecs1()', 1000)
現在我想添加一個名爲「測試時間限制」,對實例的用戶只有60分鐘,做測試的新功能:使計數器應開始計數下。
相關:審查倒計時計時器http://codereview.stackexchange.com/questions/10290/countdown-in-javascript –