使用JavaScript写的倒计时,使用setInterval调用对象自身方法报 Maximum call stack size exceeded问题
[code="javaScript"]<!doctype html>
Title
00 00 00
00 00 00
<br> function CounterDown(id,endtime){<br> this.id=id;<br> this.endtime=new Date(endtime).getTime();<br> this._countTime();<br> }<br> CounterDown.prototype={<br> _countTime:function(){<br> var timmer;<br> var now =new Date().getTime(); <br> now = now+1000;<br> var teamTimeId = this.id,<br> endtime = this.endtime,<br> lasttime = (parseInt(endtime)-parseInt(now)) / 1000,<br> days = Math.floor(lasttime / (24 * 3600)),<br> lastSec = (lasttime - days * 24 * 3600),<br> hours = Math.floor(lastSec/3600),<br> minutes = Math.floor((lastSec - hours * 3600)/60),<br> seconds = Math.floor(lastSec - (hours * 3600) - (minutes * 60));</p> <pre><code> if(lasttime <= 0){ clearInterval(timmer); $('#'+teamTimeId).html("<span><b>0</b><b>0</b></span>天<span><b>0</b><b>0</b></span>时<span><b>0</b><b>0</b></span>分<span><b>0</b><b>0</b></span>秒"); }else{ day_0=parseInt(days/10); day_1=parseInt(days%10); hours_0=parseInt(hours/10); hours_1=parseInt(hours%10); minutes_0=parseInt(minutes/10); minutes_1=parseInt(minutes%10); seconds_0=parseInt(seconds/10); seconds_1=parseInt(seconds%10); var timerhtml = ""; timerhtml += "<span><b>" + day_0+"</b><b>"+day_1 + "</b></span>天"; timerhtml += "<span><b>" + hours_0+"</b><b>"+hours_1 + "</b></span>时"; timerhtml += "<span><b>" + minutes_0+"</b><b>"+minutes_1 + "</b></span>分"; timerhtml += "<span><b>" + seconds_0+"</b><b>"+seconds_1 + "</b></span>秒"; $('#'+teamTimeId).html(timerhtml); } timmer=setInterval(this._countTime,1000); } }; new CounterDown('m1',"2014/01/01 10:10:10"); </script> </body> </code></pre> <p></html>[/code]<br> 在浏览器控制台报如下错误:</p> <p>[img]<a href="http://dl2.iteye.com/upload/attachment/0090/5946/f09d22c5-f35a-3685-8338-5caccad91105.png%5B/img%5D">http://dl2.iteye.com/upload/attachment/0090/5946/f09d22c5-f35a-3685-8338-5caccad91105.png[/img]</a></p> <p>请JavaScript高手看看是怎么回事,要怎么解决才好,谢谢!</p>