2013-10-15 64 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