<!DOCTYPE html>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="skin/jquery.js"></script>
<SCRIPT >
//
document.onkeydown = function() {
if(event.keyCode==116) {
event.keyCode=0;
event.returnValue = false;
}
};
document.oncontextmenu = function() {
event.returnValue = false;
};
if (window.Event)
document.captureEvents(Event.MOUSEUP);
function nocontextmenu() {
event.cancelBubble = true
event.returnValue = false;
return false;
}
function norightclick(e) {
if (window.Event) {
if (e.which == 2 || e.which == 3)
return false;
}else if (event.button == 2 || event.button == 3){
event.cancelBubble = true
event.returnValue = false;
return false;
}
}
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
$(function(){
var totleSecond = initTimer();
startTime(totleSecond); //开始倒计时
})
function initTimer(){
var totleSecond = Number($("#remainingTime").val()) //获取上图的input的剩余时间
return totleSecond;
}
function startTime(totleSecond){
$("#time").text(formatTime(totleSecond));
var timer = setInterval(function(){
totleSecond -= 1 ;
$("#remainingTime").val(totleSecond); //给上图的input更新剩余时间
if(totleSecond >=0 ){
$("#time").text(formatTime(totleSecond));
}else{
//AutoSubmit();
alert("考试结束!")
clearInterval(timer);
$("#remainingTime").val("");
}
},1000)
}
function formatTime(totleSecond){
var hour = Math.floor(totleSecond/3600);
var minute = Math.floor((totleSecond%3600)/60);
var second = Math.floor(totleSecond%60);
hour = formatTimeNumber(hour);
minute = formatTimeNumber(minute)
second = formatTimeNumber(second);
return (hour +":"+minute+":"+second)
}
function formatTimeNumber(number){
if(number<10){
return "0"+number;
}else{
return number;
}
}
</SCRIPT>
</head>
<body>
<input id="remainingTime" value="10"/>
<div id="time"></div>
</body>
</html>