<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> timmer</title>
</head>
<body>
<div id="timer"></div>
</body>
</html>
<script>
var maxtime = 2*60*60;
function countdown(){
hours = Math.floor( maxtime /3600 );
minutes = Math.floor( maxtime /60 );
minutes = minutes%60;
seconds = Math.floor( maxtime %60);
showtime = document.getElementById('timer');
showtime.innerHTML = "距离结束还有:" + hours + "时" + minutes +"分" + seconds + "秒";
maxtime--;
}
timer = setInterval(countdown,1000);
<html lang="en">
<head>
<meta charset="UTF-8">
<title> timmer</title>
</head>
<body>
<div id="timer"></div>
</body>
</html>
<script>
var maxtime = 2*60*60;
function countdown(){
hours = Math.floor( maxtime /3600 );
minutes = Math.floor( maxtime /60 );
minutes = minutes%60;
seconds = Math.floor( maxtime %60);
showtime = document.getElementById('timer');
showtime.innerHTML = "距离结束还有:" + hours + "时" + minutes +"分" + seconds + "秒";
maxtime--;
}
timer = setInterval(countdown,1000);
</script>
关键点:
hours = Math.floor( maxtime /3600 );
minutes = Math.floor( maxtime /60 );
minutes = minutes%60;
seconds = Math.floor( maxtime %60);