2013-10-15 62 views
1

當我看到它「活」它只崩潰,裏面jsbin似乎是工作隨機Javascript文本崩潰,爲什麼?

var counter = 1; 
var out = function nextNum() { 
counter++; 
var numArray = ["1","2","3"]; 
$('<span id="news' + counter + '" style="display:block; width:20px; height:20px;" />') 
.html(Math.floor(Math.random()*numArray.length)).appendTo('.div1') 
.hide().fadeIn(100, function(){if(counter <= 20) nextNum();});}; 
(out)(); 


setInterval(rnd,1000); 
function rnd() { 
var letter = ["1","2","3"]; 
for (var spanum = 1;; spanum++) 
$("#news" + spanum).html(Math.floor(Math.random()*letter.length));} 

http://jsbin.com/IQuxevu/4/edit

我到底做錯了什麼?

+3

你能否也請在問題中發佈代碼? – frenchie

+0

也許使用'console'? – DhruvPathak

+1

請修復您的鏈接。 –

回答

1

。在你的代碼中的無限循環:

for (var spanum = 1;; spanum++) 

有內循環沒有break。它適用於JSFiddle,因爲控制檯警告中提出了一個無限循環保護

+0

對!我現在修復爲(var spanum = 1; spanum <= 20; spanum ++) – Kolozz

+0

非常有用的回答在這裏循環js:http://stackoverflow.com/questions/3010840/loop-through-array-in-javascript – KnowHowSolutions