<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title></title>
<link href="../frontstage/css/link.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" bordercolor="black" align="center" cellpadding="0" cellspacing="0"> 
<tr> 
<td align="right"> 
<table> 
<tr> 
<td> 
<div id="d" style="position:absolute;border: 1px #FF00FF solid;width:145px;"> 
<table><tr><td>剩余考试时间:</td><td id="nowTime" style="color:blue"> </td></tr></table></div> 
</td> 
</tr> 
</table> 
</td> 
<td width="10%"></td> 
</tr> 
</table> 
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
a
<br>
</body>
<script language="javascript"> 
var allTime = 3600;//倒计时的时长
var intervalID; //停止的时机
function changeTime(){
var nowHour = parseInt(allTime/3600);
if(nowHour<10) nowHour = "0" + nowHour;
var nowMin = parseInt((allTime%3600)/60);
if(nowMin<10) nowMin = "0" + nowMin;
var nowSoc = parseInt((allTime%3600)%60)%60;
if(nowSoc<10) nowSoc = "0" + nowSoc;
var nowTime = nowHour + ":" + nowMin + ":" + nowSoc;
document.getElementById("nowTime").innerText = nowTime;
//时间到自动提交
if(allTime==0){
//dosubmitclick(document.formName,'../testquestion/testQuestionExamResult.jsp','testEnd');
formsubmit();
clearInterval(intervalID);
}
if(allTime==300){
remind();
}
allTime--;
if(allTime==-1){
allTime = 0;
}
}
//最后五分钟提醒
function remind(){
alert("离考试结束还有5分钟,请尽快答题,时间到后系统会自动提交!");
return;
}
setInterval("changeColor()", 1000);
intervalID = setInterval("changeTime()", 1000);//改变倒计时的颜色
var col;
function changeColor(){
if(col=="red"){
col = "blue";
document.getElementById("nowTime").style.color = col;
}else if(col=="blue"){
col = "green";
document.getElementById("nowTime").style.color = col;
}else{
col = "red";
document.getElementById("nowTime").style.color = col;
}
}
</script> 
<script type="text/javascript"  charset="utf-8"> 
var eDiv=document.getElementById("d");
eDiv.style.setAttribute("position","absolute");
eDiv.style.setAttribute("right","90px");
eDiv.style.setAttribute("top","190px");
</script> 
</html>

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gbk">
    <title></title>
    <link href="../frontstage/css/link.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <table width="100%" border="0" bordercolor="black" align="center" cellpadding="0" cellspacing="0">  
    <tr>  
    <td align="right">  
    <table>  
    <tr>  
    <td>  
    <div id="d" style="position:absolute;border: 1px #FF00FF solid;width:145px;">  
    <table><tr><td>剩余考试时间:</td><td id="nowTime" style="color:blue"> </td></tr></table></div>  
    </td>  
    </tr>  
    </table>  
    </td>  
    <td width="10%"></td>  
    </tr>  
    </table>  
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    a
    <br>
    </body>
    <script language="javascript">  
    var allTime = 3600;//倒计时的时长
    var intervalID; //停止的时机
    function changeTime(){
    var nowHour = parseInt(allTime/3600);
    if(nowHour<10) nowHour = "0" + nowHour;
    var nowMin = parseInt((allTime%3600)/60);
    if(nowMin<10) nowMin = "0" + nowMin;
    var nowSoc = parseInt((allTime%3600)%60)%60;
    if(nowSoc<10) nowSoc = "0" + nowSoc;
    var nowTime = nowHour + ":" + nowMin + ":" + nowSoc;
    document.getElementById("nowTime").innerText = nowTime;
    //时间到自动提交
    if(allTime==0){
    //dosubmitclick(document.formName,'../testquestion/testQuestionExamResult.jsp','testEnd');
    formsubmit();
    clearInterval(intervalID);
    }
    if(allTime==300){
    remind();
    }
    allTime--;
    if(allTime==-1){
    allTime = 0;
    }
    }
    //最后五分钟提醒
    function remind(){
    alert("离考试结束还有5分钟,请尽快答题,时间到后系统会自动提交!");
    return;
    }
    setInterval("changeColor()", 1000);
    intervalID = setInterval("changeTime()", 1000);//改变倒计时的颜色
    var col;
    function changeColor(){
    if(col=="red"){
    col = "blue";
    document.getElementById("nowTime").style.color = col;
    }else if(col=="blue"){
    col = "green";
    document.getElementById("nowTime").style.color = col;
    }else{
    col = "red";
    document.getElementById("nowTime").style.color = col;
    }
    }
    </script>  
    <script type="text/javascript" charset="utf-8">  
    var eDiv=document.getElementById("d");
    eDiv.style.setAttribute("position","absolute");
    eDiv.style.setAttribute("right","90px");
    eDiv.style.setAttribute("top","190px");
    document.documentElement.onscroll = function(){
        document.getElementById("d").style.top = 190 + document.documentElement.scrollTop + "px";}
    </script>  
    </html>