代碼哪里寫錯了,為什么stop按鈕沒有作用?
<!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;
? ?}
??
? ?function timestart(){
? ? ?var timeshow=setInterval("clock()",1000);}
? ? function timestop(){
? ? ? var timestop=clearInterval("timestart()");
? ?}
</script>
</head>
<body>
? <form>
? ? <input type="text" id="clock" size="50" ?/>
? ? <input type="button" value="Stop" onclick="timestop()" ?/>
? ? <input type="button" value="Start" onclick="timestart()" ?/>
? </form>
</body>
</html>
2016-08-23
這上面有時候驗證代碼并沒有什么用
2016-08-22
clearInterval函數(shù)的參數(shù)應(yīng)該是setInterval函數(shù)返回的timer ID, 在你的代碼中應(yīng)該就是timeshow變量。另外,如果需要在timestop函數(shù)中使用這個timeshow變量,這個變量應(yīng)該在timestart函數(shù)之外聲明。
具體參考:http://www.w3school.com.cn/jsref/met_win_setinterval.asp