最近在做一个网上考试系统,刚开始就遇到一个问题:如何显示考试的剩余时间?如果考生不刷新页面那是相当的简单,只要一个js函数就能搞定。关键考生随时可能刷新。我是采用cookie解决这个问题的,希望给遇到同样问题的同学一个帮助。不说了,直接贴源代码: <html> <head> <title>网页上在线考试时间</title> <meta http-equiv="content-Type" content="text/html;charset=gb2312"> <mce:script language="JavaScript"><!-- var timerID = null; function startclock(){ //获取当前的时间 var now = new Date(); //得到应该提交试卷的时间,并且把他写入cookie之中 var date1 = new Date(now.getYear(), now.getMonth(), now.getDate(), now.getHours()+2, now.getMinutes(), now.getSeconds(),now.getMilliseconds()); SetCookie('submitPaperTime',date1); //取得cookie之中的时间 var date2=getCookie('submitPaperTime'); now1 = new Date(date2); //得到用户刷新时的时间 var now2 = new Date(); timeLeft = (now1.getHours()-now2.getHours())*60+n