<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<input type="button" value="开始计时" onClick="start()">
<input type="text" id="txt">
<input type="button" value="停止计时" onClick="stop()">
</body>
<script type="text/javascript">
var c=0;
var t;
function start()
{
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("start()",1000);
}
function stop()
{
clearTimeout(t);
}
</script>
</html>