做一个秒表
做一个秒表的话 如果在1.XX秒按下停止 如何在开始时继续从1.xx秒开始计时 而不是重新从1秒开始计时?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>定时器</title>
<script type="text/javascript">
var attime=0;
function clock() {
attime++;
if (attime<60) {
document.getElementById('text').value=attime+"秒";
}
else{
document.getElementById("text").value=Math.floor(attime/60)+"分"+(attime-60)+"秒"
}
}
function start(){
i=setInterval(clock,1000)
}
function stop(){
clearInterval(i)
}
function restart() {
document.getElementById('text').value=0+"秒";
attime=0;
clearInterval(i);
}
</script>
</head>
<body>
<form>
<input type="text" size="100" id="text" value="0秒"></input>
<input type="button" value="开始" onclick="start()"></input>
<input type="button" value="停止" onclick="stop()"></input>
<input type="button" value="重置" onclick="restart()"></input>
</form>
</body>
</html>