如下代码,为什么点击开始按钮,然后点更改时间间隔按钮,这时再点停止按钮时就失效了。点开始后再点停止,就能正常停止。 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>定时函数</title> <script type="text/javascript"> var n = 0; var timer; function t() { document.getElementById('b').innerHTML = '数字:' + (++n); } function kaiShi() { timer = setInterval("t()",1000); } function quit() { var tui = clearInterval(timer); } function gai() { timer = setInterval("t()",500); } </script> </head> <body> <label id='b'></label> <input type="button" name="" value="start" onclick="kaiShi()"> <input type="button" name="" value="停止" onclick="quit()"> <input type="button" name="" value='更改时间间隔为0.5秒' onclick="gai()"> </body> </html>
super_mb
woshiajuana
相关分类