<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script type="text/JavaScript"> var stingTime;
var timeLeft = 60 * 60 * 1000;
function countTime()
{
document.getElementById("hehe").disabled=true; if(timeLeft == 0)
{
alert("时间到!");
return;
}
var startMinutes = parseInt(timeLeft / (60 * 1000), 10);
var startSec = parseInt((timeLeft - startMinutes * 60 * 1000)/1000)
document.getElementById("timeDiv").innerHTML = "剩余时间:" + startMinutes + "分钟" + startSec + "秒";
timeLeft = timeLeft - 1000;
setTimeout('countTime()',1000);
} </script> </head>
<body>
<input type='button' value='开始考试' onclick='countTime();' id='hehe'>
<div id='timeDiv'></div>
</body> </html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script type="text/JavaScript"> var stingTime;
var timeLeft = 60 * 60 * 1000;
function countTime()
{
document.getElementById("hehe").disabled=true; if(timeLeft == 0)
{
alert("时间到!");
return;
}
var startMinutes = parseInt(timeLeft / (60 * 1000), 10);
var startSec = parseInt((timeLeft - startMinutes * 60 * 1000)/1000)
document.getElementById("timeDiv").innerHTML = "剩余时间:" + startMinutes + "分钟" + startSec + "秒";
timeLeft = timeLeft - 1000;
setTimeout('countTime()',1000);
} </script> </head>
<body>
<input type='button' value='开始考试' onclick='countTime();' id='hehe'>
<div id='timeDiv'></div>
</body> </html>
name=clock> <INPUT type=hidden size=50 name=times>
<%
Session("tryTime")="2008/9/9 09:50:00" '这里必须是设定的一个时间,你可以是在登陆的时候设置
TimeGet=Session("tryTime")''这是ASP控制的时间
%>
<SCRIPT language=JavaScript>
var id, iM = 0, iS = 1;
var start1 ="<%=TimeGet%>";
var start=new Date(start1)
if (document.myform.times.value==""){
starts=start.getTime();
}else{
starts=document.myform.times.value;
}
//document.myform.clock.value=start.getSeconds();
function go()
{
now = new Date();
time = (2700000-(now.getTime()-starts))/1000;
//time = (10000-(now.getTime()-starts))/1000;
time = Math.floor( time);
iS = time % 60;
iM = Math.floor( time / 60); if ( iS < 10){
document.myform.clock.value = " " + iM + ":0" + iS;
}else{
document.myform.clock.value = " " + iM + ":" + iS;
}
document.myform.times.value =starts;
if (time==300){
alert("请抓紧时间答题,距交卷还有5分钟。");
}
if (time==0){
alert("时间到,请交卷。");
window.location="test.asp?gopage=jiaojuan&choose=" + document.form1.choose.value;
}
id = setTimeout( "go()", 1000); }
go();
</SCRIPT>
</form>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<form name=myform><input type=text name=random value=""
style="background-color: #ccffff; border: 1px solid #d3d3d3; font-size: 50pt;; height: 70px; width: 75px;">
<input type=button value="begin" onclick=begin() name=button1> <input
type=button value="end" onclick=end() name=button2></form>
</BODY>
<script language=javascript>
var flg
function begin() {
flg = 1
nothing()
}
function end() {
flg = 0
}
function nothing() {
var x = 51
while (x > 50) {
x = Math.random()
x = Math.floor(x * 100 / 2) + 1
}
document.myform.random.value = x
if (flg == 0)
return false
setTimeout("nothing()", 40)
}
</script>
</HTML>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script type="text/JavaScript"> var stingTime;
var timeLeft = 60 * 60 * 1000;
function countTime()
{
document.getElementById("hehe").disabled=true;
document.getElementById("hehe").value="交卷";
if(timeLeft == 0)
{
alert("时间到!");
return;
}
if(timeLeft <=45 *60*1000)
{
document.getElementById("hehe").disabled=false;
}
var startMinutes = parseInt(timeLeft / (60 * 1000), 10);
var startSec = parseInt((timeLeft - startMinutes * 60 * 1000)/1000)
document.getElementById("timeDiv").innerHTML = "剩余时间:" + startMinutes + "分钟" + startSec + "秒";
timeLeft = timeLeft - 1000;
setTimeout('countTime()',1000);
} </script> </head>
<body>
<input type='button' value='开始考试' onclick='countTime();' id='hehe'>
<div id='timeDiv'></div>
</body> </html>
var maxtime = 24*60*60 //24天,按秒计算,自己调整!
function CountDown(){
if(maxtime>=0){
day=Math.floor(maxtime/3600);
minutes = Math.floor(maxtime/1440);
seconds = Math.floor(maxtime%60);
msg = "距离考试还有"+day+"天"+minutes+"分"+seconds+"秒";
document.all["timer"].innerHTML=msg;
if(maxtime == 5*60) alert('注意,还有5分钟!');
--maxtime;
}
else{
clearInterval(timer);
alert("时间到,结束!");
}
}
timer = setInterval("CountDown()",1000);
</SCRIPT>
<div id="timer" style="color:red"></div>
=========以上的都是在不刷新页面的前提下完成的。如果想刷新后也可以,可以通过 Cookie来实现
具体Cookie操作见:http://topic.csdn.net/u/20090424/15/407d498a-7286-46d4-92d7-fab1cf54c5ef.html
5楼我的回复,Cookie基本操作