time并不會(huì)增加
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>計(jì)時(shí)器</title>
<script type="text/javascript">
? ?function clock(){
? ? ? var time=0;? ? ?
? ? ? time++;
? ? ? document.getElementById("clock").value = time;
? ?}
? ? ?var sixsixsix=setInterval(clock,100);
</script>
</head>
<body>
? <form>
? ? <input type="text" id="clock" size="50"? />
? ? <input type="button" value="Stop"? onclick="clearInterval(sixsixsix)"/>
? </form>
</body>
</html>
2019-05-25
因?yàn)槊看螆?zhí)行time都會(huì)初始化為0,然后再加1.吧vat time=0移到方法外面就行了。但是stop停不下來。chrome瀏覽器。