為什么參數i是必須的?
<!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; ???} ???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
參數i必須,你必須指明停止對象。你這么寫onClick="clearInterval(setInterval("clock()",1000))"(你這里語法有問題,雙引號中不能用雙引號要用單引號,應這樣onClick="clearInterval(setInterval('clock()',1000))"。)相當于 同時啟動和停止=沒效果