為什么參數(shù)i是必須的?
<!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=new?Date();?????????????????????
??????document.getElementById("clock").value?=?time;
???}
???setInterval("clock()",1000);
</script>
</head>
<body>
??<form>
????<input?type="text"?id="clock"?size="50"??/>
????<input?type="button"?value="Stop"?onClick="clearInterval(setInterval("clock()",1000))"?/>
??</form>
</body>
</html>這樣為什么不行?
2015-04-02
參數(shù)i必須,你必須指明停止對(duì)象。你這么寫onClick="clearInterval(setInterval("clock()",1000))"(你這里語(yǔ)法有問(wèn)題,雙引號(hào)中不能用雙引號(hào)要用單引號(hào),應(yīng)這樣onClick="clearInterval(setInterval('clock()',1000))"。)相當(dāng)于 同時(shí)啟動(dòng)和停止=沒(méi)效果