2011-03-29 132 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