黑夜的白_羊
2020-06-08 22:40
<!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;
function start() {
i = setInterval("clock()",100);
}
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="Start" onclick="start()" />
</form>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计时器</title>
<script type="text/javascript">
var s=false;
function clock(){
var time=new Date();
document.getElementById("clock").value = time;
}
var i=setInterval(clock,1000);
function fc()
{
if(s)
{
s=false;
i=setInterval(clock,1000)
}else
{
s=true;
clearInterval(i);
}
}
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="50" />
<input type="button" value="Stop" onclick="fc()" />
</form>
</body>
</html>
再点停止就失效了
看到有好多人问继续暂停继续暂停怎么搞,就这么搞吧,马马虎虎
JavaScript进阶篇
468060 学习 · 21891 问题
相似问题