2011-03-29 130 views
1

目前我使用将参数传递给setTimeout?

function showGrowl(lastNumber) { 
    var num = lastNumber; 
    //keep generating a random number untill it is not the same as the lastNumber used 
    while((num = Math.ceil(Math.random() * 3)) == lastNumber); 

    //create a clone of the chosen notification 
    var clone = $('.notification.n' + num).clone(); 

    //show the clone 
    clone.appendTo('#contain').show('fast', function() { 

    //10 seconds after showing, hide the notification 
    setTimeout(function() { 
     clone.hide('fast', function() { 

     //once it is hidden remove it 
     clone.remove(); 

     //then two seconds later show a new notification 
     setTimeout(function() { 
      showGrowl(lastNumber) 
     }, 2000); 
     }) 
    }, 10000); 
    }); 
} 

然而lastNumber始终是不确定的,当它再次调用功能,有什么做我需要做的,这样lastNumber定义?

+0

lastNumber永远不会在此脚本中增加或更改,感觉不对 – Alp 2011-03-29 01:54:54

回答

2

你不应该做任何特殊的事情才能够访问在setTimeout

但是,我认为你的意思是在setTimeout内使用num而不是lastNumber