当我把计时代码的setTimeout改成setInterval之后
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <script type="text/javascript"> var num=0; function numCount(){ document.getElementById('txt').value=num; num=num+1 setTimeout('numCount()',1000) } </script> <body> <input type="text" name="txt" id="txt" /> <input type="button" name="click" value="start" onclick="numCount()" /> </body> </html>
改成setInterval之后:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <script type="text/javascript"> var num=0; function numCount(){ document.getElementById('txt').value=num; num=num+1 setInterval('numCount()',1000) } </script> <body> <input type="text" name="txt" id="txt" /> <input type="button" name="click" value="start" onclick="numCount()" /> </body> </html>
执行后的结果是:0,1,3,7,15,31,63...
求解其具体计算步骤,不理解为什么是这样的结果。
希望各位高手指点迷津!
谢谢!!
祝看到的各位,生活愉快,工作顺利!!!