2014-01-16 28 views
0

我有這個功能,並且我試圖在它再次運行時將wordtype字符串變量傳遞迴相同的函數。在自引用函數中傳遞字符串變量

現在,除了第一次運行(當我實際送入字符串時) - 它顯示爲undefined爲wordtype。我這樣稱呼它:rotateWordsA('nouns');

我該如何讓rotateWordsA(wordtype);實際上將字符串傳回給下一輪動畫?

i=0; 
    function rotateWordsA(wordtype){ 
     console.log(wordtype); 
     var xyz = "#"+wordtype+" div."+i; 
     //console.log(xyz); 

     $("#"+wordtype+" div."+i).fadeOut(1000).hide(); 
     //alert('hi'); 
     i++; 
     //alert(i); 
     if($("#"+wordtype+" div."+i).length){ 
      prev = i-1; 
      $("#"+wordtype+" div."+prev).fadeOut(1000).hide("slow"); 
      $("#"+wordtype+" div."+i).fadeIn(1000).show(); 
      $("#"+wordtype+" div."+i).delay(1000).animate({ 
           //display: "show", 
           //left: "+=500", 
           opacity: 1 
           }, 1000, function(){ 
           setTimeout(function(){rotateWordsA()}, 2500) 

           }); 

         } 
         else{ 

          i=0; 
          rotateWordsA(wordtype); 
         } 
    } 

回答

3

你是不是傳遞變量的setTimeout

​​
+0

是以函數調用。謝謝你加入snark。只要我問了這個問題,我就注意到了未通過的變量。謝謝@Satpal! – itamar

相關問題