下面是考试的时间自动控制程序(便于演示只设了60秒钟,实际应用应以系统调出试卷的考试时间为准!):
<SCRIPT language=JavaScript> <!-- Write by HEKAI for TestTimeContorl var timerID = null;var timerRunning = false var stardate = new Date();var startime = gettotalsecond(stardate) var totaltime = 60; var lasttime;var facetime function Stepclock(){ // hk made by himself if(timerRunning) clearTimeout(timerID) timerRunning = false } function startclock(){ Stepclock();showtime() } function gettotalsecond(getdate){ var hours = getdate.getHours() var minutes = getdate.getMinutes();var seconds = getdate.getSeconds() var gettotalsecond = seconds + minutes * 60 + hours * 3600 return(gettotalsecond) } function showtime(){ var now = new Date();var timeValue = gettotalsecond(now) document.clock.face.value = timeValue - startime facetime = document.clock.face.value;lasttime = totaltime - facetime document.clock.sytime.value = lasttime timerID = setTimeout("showtime()",1000) timerRunning = true if (lasttime == 20){ for(i=1;i<=3;i++){ alert('考试时间只剩下最后20秒!')}} if (lasttime == 0){ for(i=1;i<=5;i++){ alert('时间完毕!请迅速交卷!!')}} if (lasttime == -10){ for(i=1;i<=10;i++){ alert('考试时间超过10秒,关闭此窗口!')}} }//--> </SCRIPT> |