停止和计时开始该怎么相互转换呢?
停止和计时开始该怎么相互转换呢?
停止和计时开始该怎么相互转换呢?
2014-11-21
//参考
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计时器</title>
<script type="text/javascript">
var attime;
function check(a){
if(a<10){
a = "0" + a;
}
return a;
}
function clock(){
var time=new Date();
attime=time.getHours() + ":" + check(time.getMinutes()) + ":" + check(time.getSeconds());
document.getElementById("clock").value = attime;
}
var stop = setInterval("clock()",1000);
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="50" />
<input type="button" value="Stop" onclick="clearInterval(stop)" /> //停止
<input type="button" value="begin" onclick="stop=setInterval('clock()',1000)" /> //恢复
</form>
</body>
</html>
举报