fantme
2019-09-22 10:16
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计时器</title>
<script type="text/javascript">
function clock(){
var time = new Date();
document.getElementById("clock").value = time;
}
var i = setInterval(clock,100);
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="50" />
<input type="button" value="Stop" onclick="clearInterval(i)"/>
<input type="button" value="continue" onclick="setInterval(i)"">
</form>
</body>
</html>
把这个替换成
<input type="button" value="continue" onclick="setInterval(clock,100);">
<!DOCTYPE HTML><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>计时器(暂停/开始)</title> <script type="text/javascript"> var timer = null; ooop(); function ooop() { if (!timer) { timer = setInterval( function clock(){ var time = new Date(); document.getElementById("clock").value = time.getHours()+":"+time.getMinutes()+":"+time.getSeconds() ;; }, 1000); } else { clearInterval(timer) timer = null; } } </script> </head> <body> <form> <input type="text" id="clock" size="50" /> <br /> <input type="button" value="StopOrOpen" onclick="ooop()" /> </form> </body> </html>
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题