<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>定时器</title>
</head>
<body>
剩余时间:<span id="timer"></span>
</body>
</html>
<script>
/*主函数要使用的函数,进行声明*/
var clock = new clock();
/*指向计时器的指针*/
var timer;
window.onload = function() {
/*主函数就在每50秒调用1次clock函数中的move方法即可*/
timer = setInterval("clock.move()", 1000);
}
function clock() {
this.s = 5400;
this.move = function() {
document.getElementById("timer").innerHTML = exchange(this.s);
this.s = this.s - 1;
if (this.s < 0) {
alert("时间到");
clearTimeout(timer);
}
}
}
function exchange(time) {
this.m = Math.floor(time / 60);
this.s = (time % 60);
this.text = this.m + "分" + this.s + "秒";
return this.text;
}
</script>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>定时器</title>
</head>
<body>
剩余时间:<span id="timer"></span>
</body>
</html>
<script>
/*主函数要使用的函数,进行声明*/
var clock = new clock();
/*指向计时器的指针*/
var timer;
window.onload = function() {
/*主函数就在每50秒调用1次clock函数中的move方法即可*/
timer = setInterval("clock.move()", 1000);
}
function clock() {
this.s = 5400;
this.move = function() {
document.getElementById("timer").innerHTML = exchange(this.s);
this.s = this.s - 1;
if (this.s < 0) {
alert("时间到");
clearTimeout(timer);
}
}
}
function exchange(time) {
this.m = Math.floor(time / 60);
this.s = (time % 60);
this.text = this.m + "分" + this.s + "秒";
return this.text;
}
</script>